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

October 2025

S M T W T F S
    1 23 4
5 678 9 1011
12 13 1415 161718
19202122232425
262728293031 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Oct. 17th, 2025 12:20 am
Powered by Dreamwidth Studios