CMPSC 122 Chapter Notes - Chapter 12: Artery Recordings, Merge Sort

46 views1 pages
sorting algorithms
sort a collection of objects such that k is not less than k and ki < ki+1 for all k in the
collection
allows for easy searching
python list class has built in sorting
Merge Sort
recursive divide and conquer
divide: if the input is above a certain threshold, divide it in two
conquer: recursively solve subproblems
combine: merge the solutions to the subproblem
divide and conquer for sorting
divide: if S has zero or one element, return it. otherwise, remove all
elements from S, put them in two sequences, each containing half the
elements of S
conquer: recursively sort the subsequences
combine: put elements back into S by merging the sorted subsequences
in order
Run time
recurrence equation
t(n) = {n <= 1 ? b : 2t(n/2) + cn}
recurrence equation becomes t(n) = 2it(n/2i) + icn
ends up as O(n log n)
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows half of the first page of the document.
Unlock all 1 pages and 3 million more documents.

Already have an account? Log in

Document Summary

Sort a collection of objects such that k is not less than k and ki < ki+1 for all k in the collection. Python list class has built in sorting. Divide: if the input is above a certain threshold, divide it in two. Combine: merge the solutions to the subproblem. Divide: if s has zero or one element, return it. otherwise, remove all elements from s, put them in two sequences, each containing half the elements of s. Combine: put elements back into s by merging the sorted subsequences in order. : 2t(n/2) + cn} recurrence equation becomes t(n) = 2it(n/2i) + icn.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents