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

November 2025

S M T W T F S
       1
23456 7 8
9 1011 12 1314 15
16171819 20 2122
23 24 2526272829
30      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Nov. 27th, 2025 07:01 am
Powered by Dreamwidth Studios