E N D
Selection Sort i void selectionSort(int[] a) { for (int i = 0; i < a.length - 1; i++) { int min = i; for (int j = i + 1; j < a.length; j++) { if (a[j] < a[min]) { min = j; } } if (i != min) { int swap = a[i]; a[i] = a[min]; a[min] = swap; } } } i min i min i min i, min i, min
Insertion Sort insertionSort(array A)begin for i := 1 to length[A] - 1 do begin value := A[ i ]; j := i - 1; while j >= 0 and A[ j ] > value do begin A[ j + 1] := A[ j ]; j := j - 1; end; A[ j + 1] := value; end;end;
Quicksort tooBigIndex tooSmallIndex Starting at the beginning of the array, we look for the first element that is greater than the pivot. (tooBigIndex) Starting from the other end we look for the first value that is less than or euqal to the pivot. (tooSmallIndex) After finding the two out-of-place elements, exchange them. tooBigIndex++ tooSmallIndex— Stop when tooBigIndex >= tooSmallIndex
tooSmallIndex tooBigIndex tooBigIndex tooSmallIndex tooBigIndex tooSmallIndex
tooSmallIndex tooBigIndex
Heapsort 45 27 42 21 23 22 35 19 4 5
For an element in arr[i]: Parent[(i-1)/2] • Left child [2i+1] • Right child [2i+2]
For an element in arr[i]: Parent[(i-1)/2] • Left child [2i+1] • Right child [2i+2]
For an element in arr[i]: Parent[(i-1)/2] • Left child [2i+1] • Right child [2i+2]
For an element in arr[i]: Parent[(i-1)/2] • Left child [2i+1] • Right child [2i+2]
For an element in arr[i]: Parent[(i-1)/2] • Left child [2i+1] • Right child [2i+2]
For an element in arr[i]: Parent[(i-1)/2] • Left child [2i+1] • Right child [2i+2]
For an element in arr[i]: Parent[(i-1)/2] • Left child [2i+1] • Right child [2i+2]
For an element in arr[i]: Parent[(i-1)/2] • Left child [2i+1] • Right child [2i+2]