From the course: Programming Foundations: Algorithms

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Implementing the merge sort

Implementing the merge sort

- [Instructor] Now that we've seen how the merge sort works in theory, let's build it in practice. So here in my editor, I'll open up the merge sort start, and you can see I have a list of unsorted integer numbers along with a function that I'm going to fill out. So the code starts by taking the dataset argument and splitting it into two arrays. Now I need to add the code that recursively calls merge sort to keep breaking these arrays down further into smaller and smaller parts. And you can see I've got my left array here and my right array here. And this is the Python syntax for getting all the values up to a certain point and the value from a certain point on. So I'm going to call merge sort on the left array, and then I'm going to call merge sort on the right array. So once that process is finished, we need to merge the results as we saw in the previous video. I have three indexes defined. I indexes into the…

Contents