Skip to content

Commit 513f919

Browse files
committed
Merge algorithm and computer science repositories
1 parent e0f822b commit 513f919

68 files changed

Lines changed: 3514 additions & 77 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Compiled languages
2+
*.o
3+
# Must be in src, because those in data should be included.
4+
/src/**/*.out
5+
6+
# Java
7+
*.class
8+
9+
# Eclipse
10+
.classpath
11+
.project

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: java
2+
install:
3+
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
4+
- sudo apt-get update -y
5+
- sudo apt-get install -y gcc-4.8 g++-4.8
6+
- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50
7+
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50
8+
script: ./test

README.md

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
# Computer Science
1+
# Algorithm cheat
22

3-
Computer science notes and tutorials.
3+
[![Build Status](https://travis-ci.org/cirosantilli/algorithms.svg?branch=master)](https://travis-ci.org/cirosantilli/algorithms)
44

5-
Educational implementations of the simpler algorithms may be found at: <https://github.com/cirosantilli/algorithms>
5+
Algorithm tutorials and simple implementations.
66

7-
1. Introduction
7+
1. Implementations
8+
1. [Getting started](getting-started.md)
9+
1. [src/](src/)
10+
1. [data/](data/)
11+
1. [test](test)
12+
1. Introduction to algorithms
813
1. [Beauty](beauty.md): beautiful things about computer science
914
1. [Algorithms](algorithms.md): starting point for those learning about algorithms
1015
1. [Recursive algorithms](Recursive algorithms.md)
@@ -14,35 +19,50 @@ Educational implementations of the simpler algorithms may be found at: <https://
1419
1. [P vs NP](p-vs-np.md)
1520
1. Data structures
1621
1. [Graph](graph.md)
22+
1. [Tree](tree.md)
1723
1. [Dijkstra](dijkstra.md)
18-
1. [Hash map](hash-map.md)
19-
1. [Heap](heap.md)
24+
1. [Map](map.md): [map.cpp](src/cpp/map.cpp), [bst.cpp](src/cpp/bst.hpp)
25+
1. [Hash map](hash-map.md): [hash_map.cpp](src/cpp/hash_map.hpp)
26+
1. [Heap](heap.md): [Heap.java](src/java/Heap.java)
2027
1. [Sorting algorithms](sort/)
21-
1. [Quicksort](quicksort.md)
28+
1. [Quicksort](quicksort.md): [QuickSort.java](src/java/QuickSort.java), [QuickSortTail.java](src/java/QuickSortTail.java), [HeapSort.java](src/java/HeapSort.java)
2229
1. [Merge sort](merge-sort.md)
2330
1. [Bubble sort](bubble-sort.md)
2431
1. Parsing, formal languages and their automatons
2532
1. [Formal language](formal-language.md)
2633
1. [Context-free grammar](context-free-grammar.md)
2734
1. [Regular grammar](regular-grammar.md)
2835
1. [Regular language](regular-language.md)
36+
1. String algorithms
37+
1. [Longest common subsequence](longest-common-subsequence.md)
38+
1. [Longest increasing subsequence](longest-increasing-subsequence.md)
39+
1. [Maximum subarray](maximum-subarray.md)
40+
1. [String search](string-search.md): [StringSearchNaive.java](src/java/StringSearchNaive.java), [KnuthMorrisPratt.java](src/java/KnuthMorrisPratt.java)
2941
1. Cryptography
3042
1. [base64](base64.md)
3143
1. [Cryptography](cryptography)
3244
1. [ECDSA](ecdsa.md)
3345
1. [GPG](gpg.md)
3446
1. [md5sum](md5sum.md)
47+
1. Linear programming
48+
1. [Change making](change-making.md)
49+
1. Out-of-core
50+
1. [tac](tac.md): [tac.c](src/c/tac.c), [Tac.java](src/java/Tac.java)
51+
1. Misc algorithms
52+
1. [Hanoi tower](hanoi-tower.md)
53+
1. [XOR-swap](xor-swap.md)
3554
1. Misc
3655
1. [Bitcoin](bitcoin.md)
3756
1. [Decimal data type](decimal-data-type.md)
3857
1. [Licenses](licenses.md)
3958
1. [Quantum computing](quantum-computing.md)
4059
1. [Security](security.md)
41-
1. [XOR-swap](xor-swap.md)
4260
1. [Bibliography](bibliography.md)
61+
1. [TODO](TODO.md)
4362

4463
## WIP
4564

65+
1. [Knapsack](knapsack.md)
4666
1. Data structures
4767
1. [Crit-bit tree](crit-bit-tree.md)
4868
1. [Disjoint set](disjoint-set.md)

TODO.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# TODO
2+
3+
Algorithms that could be included:
4+
5+
- <http://stackoverflow.com/questions/2113795/quickest-way-to-find-missing-number-in-an-array-of-numbers>
6+
7+
Find the missing number of an increasing sequence that has been mixed up.
8+
9+
E.g., start with:
10+
11+
1 2 3 4 5 6
12+
13+
Mix up:
14+
15+
6 3 5 4 2 1
16+
17+
Remove an unknown number:
18+
19+
6 5 4 2 1
20+
21+
Which number was removed?
22+
23+
Solution: sum up, use the sum formula, take difference.
24+
25+
- <http://stackoverflow.com/questions/3492302/easy-interview-question-got-harder-given-numbers-1-100-find-the-missing-numbe>
26+
27+
Same as above, but remove 2 numbers instead.
28+
29+
- <http://stackoverflow.com/questions/1586858/find-the-smallest-integer-not-in-a-list>
30+
31+
Find the smallest non-negative integer *not* in an unsorted array of length `N`.
32+
33+
The array is stored in RAM.
34+
35+
Application: generate unique IDs in a system where any ID can be removed.
36+
37+
Solution intuition:
38+
39+
- `N` is the largest possible value in case of an increasing sequence. This means that you can throw away any number larger than `N`.
40+
- if the array were sorted, it would be easy.
41+
- there are non-comparison sorting algorithms for integers in a fixed range that perform $O(N)$ time $O(1)$ memory.
42+
43+
Solution: 2 passes, first try to put every number smaller than `N` in the array position with same value as the number. If already occupied by another number, do the same for the other number. Throw away anything larger than `N`.
44+
45+
- <https://en.wikipedia.org/wiki/Out-of-core_algorithm>. We currently have `tac`. Find more.
46+
47+
- <http://en.wikipedia.org/wiki/Partition_problem>. Partition a multiset into two sub-multisets such that the sum of each sub-multiset is equal. NP-complete.
48+
49+
Many not have a solution, which leads to the optimization version: minimize the difference. NP-hard.
50+
51+
- <http://en.wikipedia.org/wiki/Stable_marriage_problem>
52+
53+
- <http://en.wikipedia.org/wiki/National_Resident_Matching_Program#Matching_algorithm>
54+
55+
- <http://en.wikipedia.org/wiki/Stable_roommates_problem>
56+
57+
Some NP-complete ones:
58+
59+
- <http://en.wikipedia.org/wiki/Karp%27s_21_NP-complete_problems>
60+
61+
- <http://en.wikipedia.org/wiki/Vertex_cover>

bibliography.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,41 @@
11
# Bibliography
22

3-
Free:
3+
## Other bibliographies
4+
5+
- <https://github.com/vhf/free-programming-books>: huge list of free books and algorithmic problem sets
6+
7+
## Free
8+
9+
- <http://algs4.cs.princeton.edu/home/>, which has lots GPL Java source. This kind soul has put the source up on GitHub: <https://github.com/aistrate/AlgorithmsSedgewick>
10+
11+
- <http://www3.cs.stonybrook.edu/~algorith/>. Links to tons of open source algorithm implementations that solve many problems. Each algorithm has a rating, and algorithms are all classified.
12+
13+
- <http://www.geeksforgeeks.org/fundamentals-of-algorithms>
14+
15+
- <http://en.wikibooks.org/wiki/Algorithm_Implementation>
16+
17+
## Non-free
418

519
- [Skiena - Algorithm Design Manual 2ed][skiena08]
620
- [Cormen - Introduction do Algorithms 2ed][cormen09]
721

8-
Non-free.
22+
## Algorithmic problem sets
23+
24+
My favorites are:
25+
26+
- [TopCoder](http://www.topcoder.com/active-challenges/develop). No solutions. 6M registered users. Money prizes. Some company proposed problems have Non Disclosure Agreements. Timed submission contests.
27+
- [HackerRank](https://www.hackerrank.com/categories/fp/intro). No solutions, 3M Round A. Timed submission contests.
28+
- [Kaggle](https://www.kaggle.com/competitions). Data science focused. No solutions. Some problems have money prizes.
29+
- [Sphere Online Judge (SPOJ)](http://www.spoj.com/problems/classical/all/). No solutions. 200K users, 10000 problems.
30+
- [Project Euler](http://projecteuler.net/problems). 350K users, only ~450 problems. No solutions. Since 2001. Probably one of the oldest around, but did not evolve much.
31+
- [UVa](http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=1). 100K registered users. No solutions. Slow website.
32+
- [CareerCup](http://www.careercup.com): Interview questions.
33+
34+
Yearly contests:
35+
36+
- [ACM International Collegiate Programming Contest](http://icpc.baylor.edu/). [Wiki](en.wikipedia.org/wiki/ACM_International_Collegiate_Programming_Contest). No solutions. Eligibility: less than five years of university education before the contest. Started in 1977. [World final problems](http://icpc.baylor.edu/worldfinals/problems).
37+
- [Google Code Jam](http://code.google.com/codejam/contests.html). Only a few solutions.
38+
- [ICFP](http://en.wikipedia.org/wiki/ICFP_Programming_Contest). One problem per year. Since 1998.
939

1040
[cormen09]: http://www.amazon.com/books/dp/0262033844
1141
[skiena08]: http://www.amazon.com/Algorithm-Design-Manual-Steven-Skiena/dp/1848000693

change-making.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Change making
2+
3+
<http://en.wikipedia.org/wiki/Change-making_problem>
4+
5+
Knapsack-like problem where:
6+
7+
- each weight is fixed to 1
8+
- the goal must be reached exactly
9+
- infinite supply of items
10+
11+
Even the feasibility is NP-complete.
12+
13+
If the input set is <http://en.wikipedia.org/wiki/Superincreasing_sequence>, like the coin denomination of most countries, then the greedy algorithm works. This is why there is cannot be a 3 euro coin: otherwise 3 + 2 + 1 = 6 > 5, and change making would be NP-complete.
14+
15+
## Implementations
16+
17+
- [make_change.cpp](src/cpp/make_change.cpp)
18+
19+
## Bibliography
20+
21+
- <https://web.archive.org/web/20131007212811/http://www.or.deis.unibo.it/kp/Chapter5.pdf>

data/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# data
2+
3+
Language agnostic test data.

data/sort/3.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
3
2+
1 2 0

data/sort/3.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0 1 2

data/sort/4.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
4
2+
1 3 2 0

0 commit comments

Comments
 (0)