CP114-Sorting lectures - Selection Sort Find the largest element in the array and exchange it with the element in the last position Find the second

CP114-Sorting lectures - Selection Sort Find the largest...

This preview shows page 1 - 15 out of 42 pages.

Selection Sort Find the largest element in the array and exchange it with the element in the last position, Find the second largest element in array and exchange it with the element in the second last position, Continue in this way until the entire array is sorted.
Image of page 1

Subscribe to view the full document.

Selection Sort 0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 4 5 6
Image of page 2
Insertion Sort The items of the array are considered one at a time, and each new item is inserted into the appropriate position relative to the previously sorted items.
Image of page 3

Subscribe to view the full document.

Insertion Sort
Image of page 4
Search Search Divide and Conquer Search Search Search Search Recall: Binary Search
Image of page 5

Subscribe to view the full document.

Sort Sort Divide and Conquer Sort Sort Sort Sort Sort Sort Sort Sort Sort Sort Sort Sort
Image of page 6
Divide and Conquer Combine Combine Combine Combine Combine Combine
Image of page 7

Subscribe to view the full document.

Divide and Conquer module sort(array) { if (size of array > 1) { split(array, firstPart, secondPart) sort(firstPart) sort(secondPart) combine(firstPart, secondPart) } }
Image of page 8
Divide and Conquer module sort(array) { if (size of array > 1) { split(array, firstPart, secondPart) sort(firstPart) sort(secondPart) combine(firstPart, secondPart) } }
Image of page 9

Subscribe to view the full document.

Divide and Conquer module sort(array) { if (size of array > 1) { split ( array , firstPart , secondPart ) sort(firstPart) sort(secondPart) combine(firstPart, secondPart) } }
Image of page 10
Divide and Conquer module sort(array) { if (size of array > 1) { split(array, firstPart, secondPart) sort ( firstPart ) sort ( secondPart ) combine(firstPart, secondPart) } }
Image of page 11

Subscribe to view the full document.

Divide and Conquer module sort(array) { if (size of array > 1) { split(array, firstPart, secondPart) sort(firstPart) sort(secondPart) combine ( firstPart , secondPart ) } }
Image of page 12
Merge Sort Sort Sort Merge
Image of page 13

Subscribe to view the full document.

array: array: size size Merge Sort tmp: tmp: tmpArrayPtr: tmpArrayPtr:
Image of page 14
Image of page 15
  • Fall '13
  • sta
  • Sort, 2 J, 3 k, 6 10 14 22 43 50 j

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

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes