Class Notes (839,092)
Canada (511,185)
CMPT 225 (60)
John Edgar (28)

CMPT 225 Week 7 Lecture 2

1 Page

Computing Science
Course Code
CMPT 225
John Edgar

This preview shows half of the first page. Sign up to view the full page of the document.
Merge - O(n) operation Have two sorted stacks want to put into one sorted stack. Do something like merge? Like partitioning, doesn't actually sort. Just brings two (sorted?) sub arrays together Array of 1 million items contains 1 million sorted subarrays!All of size one. Now, start merging them in pairs. Then take pairs of these sorted subarrays of size two and merge. Subarrays will double in size each time. Number of steps: log(n) void ms(arr, low, high) { if (low < high) { mid = (low + high) / 2; ms(arr, low, mid); ms(arr, mid + 1, high); merge(arr, low, mid, mid+1, high); // low, mid = subarray 1, mid+1, high = subarray 2 } } Make recursive calls until you're getting to subarrays of size 1, then merge back up Merge process ca
More Less
Unlock Document

Only half of the first page are available for preview. Some parts have been intentionally blurred.

Unlock Document
You're Reading a Preview

Unlock to view full version

Unlock Document

Log In


Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.