From the course: Complete Guide to Parallel and Concurrent Programming in Python

Unlock the full course today

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

Solution: Merge sort in Python

Solution: Merge sort in Python

(lively 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_merged sort function is called the first time without any additional…

Contents