You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
-<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.
-[Cormen - Introduction do Algorithms 2ed][cormen09]
7
21
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.
-[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.
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.
0 commit comments