14SortingAlgorithms - Selection Sort – what’s actually...

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

View Full Document Right Arrow Icon
Gros Morne, Newfoundland CSE 114 – Computer Science I Sorting Algorithms
Image of page 1

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

View Full Document Right Arrow Icon
Midterm Exam 2 SBCS Review Session Wednesday 7pm-8:30pm In CS 2129
Image of page 2
Sorting - The Selection Sort Algorithm Algorithm (non-decreasing sort): Repeat the following for each element at position j in the array for j = 0 to j = length-2: 1. Find the index of the "minimum" element from position j to length-1. 2. Swap the element at position j with the minimum element. (Why don't we do this for the last element at position j = length-1?)
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Selection Sort – what’s actually happening 5 2 5 8 4 2 7 1 1 2 5 8 4 2 7 5 1 2 5 8 4 2 7 5 1 2 2 8 4 5 7 5 1 2 2 4 8 5 7 5 1 2 2 4 8 5 7 5 1 2 2 4 8 7 5 5 1 2 2 4 8 7 5 5 Selection Sort Example public static void selectionSort(int data) { int j, k, min_index; for (j = 0; j <=data.length-2; j++) { min_index = j; for (k = j+1; k <= data.length-1; k++) if (data[k] < data[min_index]) min_index = k; int temp = data[j]; data[j] = data[min_index]; data[min_index] = temp; } }...
View Full 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