This lesson continues our exploration of sorting by examining a new approach. We'll start with a simple but powerful observation, and then examine how to build on it to create a complete sorting algorithm. This will also represent our first sorting algorithm that achieves best-case sorting performance! What are we waiting for?
merge
We'll begin with an observation.
Next, let's implement merge
on two int
arrays and confirm our hunch about its performance.
Next let's consider how to design a sorting algorithm that utilize our merge
method.
We'll also use this as a chance to point out how we can apply recursive algorithms on arrays, rather than trees, which we've used in the past.
Finally, let's analyze the performance of Mergesort. This is an interesting case! Let's walk through it carefully.
Need more practice? Head over to the practice page.