Titlul: Binary Search Shortlist Scris de: Cosmin Negruseri din Mai 16, 2014, 08:25:41 http://www.infoarena.ro/blog/binary-search-shortlist
Titlul: Răspuns: Binary Search Shortlist Scris de: Alex Velea din Mai 16, 2014, 09:24:53 #3 The numbers are uniq?
Titlul: Răspuns: Binary Search Shortlist Scris de: Cosmin Negruseri din Mai 16, 2014, 09:33:26 yes, thanks
Titlul: Răspuns: Binary Search Shortlist Scris de: Radu Grigore din Mai 16, 2014, 13:51:48 One more:
11. Find some minimal subset A of S that has a monotone property p. The property p is given as a function. It is expensive to call this function, so you want to minimize the number of calls in the worst case. (p monotone = if p holds for a set, it also holds for all supersets; A minimal = A has property p, but no proper subset of A does) The following solution is too slow because it makes |S| calls even if A is tiny: Cod: find(S, p) Titlul: Răspuns: Binary Search Shortlist Scris de: Cosmin Negruseri din Mai 17, 2014, 11:20:29 I can do it in k log n queries, where k is the average size of a minimal subset and n is the size of S. I don't think one can solve it faster than k queries.
Titlul: Răspuns: Binary Search Shortlist Scris de: Alex Velea din Mai 17, 2014, 14:09:51 First i need to say that #8 is my favourite problem :D
So here it is ... let's asume that the arrays are indexed from 1 to n, m O(logK) First we need to make a quick observation. The first k elements in the union form a compact section in the 2 arrays. That means that one array contains at least [k/2] elements. let x = k/2 Cod: We compare A[x] with B[x]. Cod: #include <cassert> Titlul: Răspuns: Binary Search Shortlist Scris de: Radu Grigore din Mai 17, 2014, 21:12:38 Cosmin's solution for #11 is probably O(k + k lg(n/k)), which is the best known.
Lots of problems reduce to #11: http://arxiv.org/abs/1402.3011 Titlul: Răspuns: Binary Search Shortlist Scris de: Andrei Geogescu din Iunie 01, 2014, 14:06:57 #3
Cod: int A[number],leftLimit = 0,rightLimit = A.lenght-1; Titlul: Răspuns: Binary Search Shortlist Scris de: Radu Grigore din Iulie 06, 2014, 19:06:29 In case anyone is curious, I wrote up the solution to my puzzle (#11):
http://rgrig.blogspot.com/2014/07/minimal-sets-over-monotone-predicates.html |