[Tutor] Merge Challenge

Raymond Hettinger python at rcn.com
Sat Oct 18 15:06:47 EDT 2003


[Gregor]
> I'm very courious about your solution.
> I tried
> 
> c=a+b
> c.sort()
> 
> and that is indeed very fast. (Trying for half an
> hour I couldn't find *any* faster one).
> Will be hard to surpass.

That's the winning solution.
Tim Peter's amazing new sort routine discovers 
the two sorted subsequences and merges them in
a tight C coded loop at O(n) runtime.

For almost any other implementation of sort, the
above solution would run at a much slower O(n log n)
speed and would be beat by even badly coded pure
python solutions running at O(n).

In case you can't tell, I'm very impressed with
Tim's sort code.



Raymond Hettinger




More information about the Tutor mailing list