SlideShare a Scribd company logo
CSE 114 – Computer Science I Sorting Algorithms Gros Morne, Newfoundland
Midterm Exam 2 SBCS Review Session Wednesday 7pm-8:30pm In CS 2129
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: Find the index of the "minimum" element from position j to length-1. 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?)
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; } }

More Related Content

PDF
02 - 04 Jan - Sorting (Continued)
PPTX
Recursion
PPT
Amortized analysis
PPT
Fundamental of Algorithms
PDF
Fundamentals of algorithms
PDF
Fuzzy control design_tutorial
PPTX
Daa unit 1
DOCX
Data Abstraction (Chapter 1)
02 - 04 Jan - Sorting (Continued)
Recursion
Amortized analysis
Fundamental of Algorithms
Fundamentals of algorithms
Fuzzy control design_tutorial
Daa unit 1
Data Abstraction (Chapter 1)

What's hot (7)

PDF
Algorithm analysis insertion sort and asymptotic notations
PDF
Quiz2 | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
DOC
modelling and simulation of second order mechanical system
PPTX
Notion of an algorithm
DOCX
Data Structures and Algorithms
Algorithm analysis insertion sort and asymptotic notations
Quiz2 | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
modelling and simulation of second order mechanical system
Notion of an algorithm
Data Structures and Algorithms
Ad

Viewers also liked (18)

PDF
Presentazione per corso Erickson
PPTX
Diseño de mándala.
PPTX
COMPASS Practice Test on Learning Express Library
ODP
Other Images
PDF
Workshop community
PDF
MU Signal Processing group
PPTX
Improved draft interview
PPT
PPT
Session 6 the cycle of abuse.2016
PDF
Icd2015 fiche chili
PPS
овочі
PPTX
Magazine brainstorm
PDF
Media Ethics: Privacy
PPTX
8. the juvenile court movement
PPT
Session 5 youth crime the media.2016
PPTX
Crime & Violence
PDF
Hello campers '15
Presentazione per corso Erickson
Diseño de mándala.
COMPASS Practice Test on Learning Express Library
Other Images
Workshop community
MU Signal Processing group
Improved draft interview
Session 6 the cycle of abuse.2016
Icd2015 fiche chili
овочі
Magazine brainstorm
Media Ethics: Privacy
8. the juvenile court movement
Session 5 youth crime the media.2016
Crime & Violence
Hello campers '15
Ad

Similar to Sorting algorithms (20)

PPTX
A Comprehensive Comparative Study and Performance Evaluation
PPTX
Lecture 13 data structures and algorithms
DOCX
Sorting
PPTX
Different Searching and Sorting Methods.pptx
PDF
201707 CSE110 Lecture 29
PPT
Unit 7 sorting
PPT
07-sorting.ppt for insertion sort and bubble sorting technquies
PPT
Data Structure (MC501)
PPTX
sorting-160810203705.pptx
PDF
L 14-ct1120
PPTX
Data structure.pptx
PPTX
Sorting and Searching - Data Structure - Notes
PPT
ds 3Sorting.ppt
PPTX
Dsa – data structure and algorithms sorting
PPTX
Unit vii sorting
PPTX
Lec 03 - Sorting.pptx
PPTX
Sorting Algorithms
PPTX
Data Structure and algorithms for software
PPT
Sorting
PPSX
Sorting and searching
A Comprehensive Comparative Study and Performance Evaluation
Lecture 13 data structures and algorithms
Sorting
Different Searching and Sorting Methods.pptx
201707 CSE110 Lecture 29
Unit 7 sorting
07-sorting.ppt for insertion sort and bubble sorting technquies
Data Structure (MC501)
sorting-160810203705.pptx
L 14-ct1120
Data structure.pptx
Sorting and Searching - Data Structure - Notes
ds 3Sorting.ppt
Dsa – data structure and algorithms sorting
Unit vii sorting
Lec 03 - Sorting.pptx
Sorting Algorithms
Data Structure and algorithms for software
Sorting
Sorting and searching

Sorting algorithms

  • 1. CSE 114 – Computer Science I Sorting Algorithms Gros Morne, Newfoundland
  • 2. Midterm Exam 2 SBCS Review Session Wednesday 7pm-8:30pm In CS 2129
  • 3. 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: Find the index of the &quot;minimum&quot; element from position j to length-1. 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?)
  • 4. 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
  • 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; } }