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 - Python Tutorial
From the course: Complete Guide to Parallel and Concurrent Programming 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
-
-
-
Welcome to the challenges39s
-
(Locked)
Challenge: Matrix multiply in Python5m 29s
-
(Locked)
Solution: Matrix multiply in Python7m 58s
-
(Locked)
Challenge: Merge sort in Python4m 18s
-
(Locked)
Solution: Merge sort in Python5m 20s
-
(Locked)
Challenge: Download images in Python2m 7s
-
(Locked)
Solution: Download images in Python4m 9s
-
-