May. 27th, 2011

juan_gandhi: (Default)
So, we have 100500 records; we need to take, say, the second 100, as if we ordered the whole set and then got those 100.

Sure we don't need to sort everything. The (recursive) solution is this:

1. take a pivot value x
2. partition the records around the pivot, so there are k below x and N-k above x.
3. find where our required range (a..b) lies: if it is inside the whole partition, fine; repeat
4. otherwise, take some from the tail of the left partition and some from the head of the right partition.

That's it, right?

Complexity: average still O(n log(n)), but the worst case is O(n*(b-a)).

Right?

bad puzzle

May. 27th, 2011 03:51 pm
juan_gandhi: (Default)
What's this sequence about? What's next?
1901 1907 1913 1931 1933 1949 1951 1973 1979 1987 1993 1997 1999 2003 2011

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

September 2025

S M T W T F S
 1 2345 6
78 9 10 111213
14 151617 181920
21222324252627
282930    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 21st, 2025 12:11 pm
Powered by Dreamwidth Studios