{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Tutorial 12

# Tutorial 12 - CS134Tutorial#12: Winter2008 CS134Tutors 1...

This preview shows pages 1–3. Sign up to view the full content.

CS 134 Tutorial #12: Sorting Algorithms and Efficiency Winter 2008 CS 134 Tutors 1.  Mergesort Here is the code for the mergesort method: public static void mergesort(Comparable[] tA, int first, int last) { if (last > first) { mid = (first+last) / 2; mergesort(tA, first, mid); mergesort(tA, mid+1, last); merge(tA, first, mid, last); * } } Question 1:  Show the contents of the given array just before the final call to merge, followed by the  final sorted contents. 1 2 0 9 6 5 4 8 7 3 ... Question 2:  Describe in English how one would implement the  merge  method, which mergesort calls  on the line indicated with an asterisk (*). You should give enough detail such that a CS 134 student  could take your description and translate it into code.

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

View Full Document
2.  Quicksort Consider the following unsorted array: Sandy Nate Ted Jason Truc Cathy Leo Mary Question 1:  What does the array look like  just after  the  first  call to  partition , using the last element  as a pivot?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern