Sorting1.4 - Merge Sort 88 52 14 31 25 98 30 23 62 79 Get...

Info icon This preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Last Updated: 4/1/10 11:16 AM CSE 2011 Prof. J. Elder - 21 - Merge Sort 88 14 98 25 62 52 79 30 23 31 Split Set into Two (no real work) 25,31,52,88,98 Get one friend to sort the first half. 14,23,30,62,79 Get one friend to sort the second half.
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Last Updated: 4/1/10 11:16 AM CSE 2011 Prof. J. Elder - 22 - Merge Sort Merge two sorted lists into one 25,31,52,88,98 14,23,30,62,79 14,23,25,30,31,52,62,79,88,98
Image of page 2
Last Updated: 4/1/10 11:16 AM CSE 2011 Prof. J. Elder - 23 - Merge-Sort ± Merge-sort on an input sequence S with n elements consists of three steps: ² Divide : partition S into two sequences S 1 and S 2 of about n / 2 elements each ² Recur : recursively sort S 1 and S 2 ² Conquer : merge S 1 and S 2 into a unique sorted sequence Algorithm mergeSort ( S ) Input sequence S with n elements Output sequence S sorted if S.size () > 1 ( S 1 , S 2 ) ³ split ( S , n /2) mergeSort ( S 1 ) mergeSort ( S 2 ) merge ( S 1 , S 2, S )
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Last Updated: 4/1/10 11:16 AM CSE 2011 Prof. J. Elder - 24 - Merging Two Sorted Sequences ± The conquer step of merge-sort consists of merging two sorted sequences
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern