html
A merge sort is a sorting algorithm that works by splitting a list into smaller sublists until each one is sorted, then merging those sublists back together in sorted order. Sounds simple, right?
But what happens when the sublists are not sorted in a consistent way? Like, say, in alphabetical order instead of numerical order?
It's like trying to build a house with mismatched bricks. It just won't stand a chance.
See, for example, the algorithmic klutz that ensues when trying to merge a sorted list of strings with a non-sorted list of integers.A merge sort relies on being able to index into an array with a consistent start and end index. But what happens when that's not the case?
It's like trying to find a specific sock in the laundry, except instead of socks, it's a list of numbers.
And just like that, the algorithm goes haywire.
See, for example, the indexing hell that occurs when the start and end indices are out of whack.