From the course: Python Parallel and Concurrent Programming Part 2

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Merge sort in Python

Solution: Merge sort in Python - Python Tutorial

From the course: Python Parallel and Concurrent Programming Part 2

Start my 1-month free trial

Solution: Merge sort in Python

(upbeat music) - [Instructor] For our solution to the merge sort challenge, we used a recursive divide and conquer approach with multiple processes conquering the task of sorting subsections of the array. For the divide phase, rather than recursively subdividing the array until it reaches single elements, we configured our base case to subdivide the array based on the number of processors in the computer. For example, if the computer only had four processors, then it would only go through two layers of subdivision to produce four sub-arrays in need of sorting. We then spawn additional processes that use the sequential merge sort algorithm to sort each of those sub-arrays and then the main process merges the results back together. By limiting the depth of recursion in our base case, we're able to use a few processes, only as many as we have processors in the system to sort large sections of the array. When the par merge sort function is called the first time, without any additional…

Contents