r/dailyprogrammer • u/oskar_s • May 16 '12
[5/16/2012] Challenge #53 [easy]
Write a function that given two sorted lists, returns a list whith the two lists merged together into one sorted list.
So, for instance, for inputs [1,5,7,8] and [2,3,4,7,9] it should return [1,2,3,4,5,7,7,8,9].
Try and make your code as efficient as possible.
19
Upvotes
View all comments
Show parent comment
0
u/Maristic May 16 '12
Actually, you're mistaken in two ways.
First, it depends entirely on the sorting algorithm used. For example, if your system's sort is Timsort or something equivalent, merging two sorted lists will be O(n), not O(n log n). So, folks coding in Python or Java are off the hook right there.
Second, even if it's O(n log n), for those writing in scripting languages that don't use something equivalent to Timsort, the question then becomes, “Is the slowdown form a log n factor compensated for by direct native implementation of sorting”, and the answer is likely “Yes”.
If you want a complaint against people calling built-in sort functionality, you'd be better off saying that question asks for something that works on lists, and thus methods written for arrays or array-lists don't count.