COMP 250 Lecture Notes - Lecture 7: Merge Algorithm, Selection Sort

67 views2 pages

Document Summary

Many recursive algorithms fit following framework: divide the problem into subproblems, conquer the subproblems by solving them recursively, combine the solution of each subproblem into the solution of the original problem. What if we want to sort elements of an array of n elements: divide the array into a left and right half, conquer each half by recursively sprting them, combine the sorted halves into a fully sorted array. The array to be sorted is 3 1 4 1 5 9 2 6 5 3 5 8 9. Divide it into 2 halves 3 1 4 1 5 9 2 6 5 3 5 8 9. Merge the two halves into a fully sorted array 1 1 2 3 3 4 5 5 5 6 8 9 9. Create a temporary array of same size as original. Keep track of two indices, a left and right half index.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions