Join and sort is four times too slow.
transcript
Correct code can still miss its budget. A parcel-delivery app found out the hard way. Always count the cost first. Here is the count.
Two gates send a million scans each. The page rebuilds the timeline every second. Its budget is a tenth of a second.
Join the two lists into one. Sort the joined list. It is correct. It is short. Now count what it costs.
A general sort makes about n log n comparisons. For two million values that is forty-two million. At a hundred million a second, that is 0.42 seconds. The budget was a tenth of a second.
The sort ignores the order each list has. It builds the order again from scratch. A merge uses the order, and takes 0.02 seconds.
The order was free. The sort threw it away. Use what the data already gives you. That is the whole idea of a merge. Full breakdown in the lecture.