Bubble Sort Example 5 1 4 2 8

Bubble Sort Example 5 1 4 2 8 1 4 2 5 8 1 5 4 2 8 1 2 4 5 8 1 4 5 2 8 1 2 4 5 8 1 4 2 5 8

Selection Sort i 63 25 12 22 i 63 11 11 11 min 25 12 i min 25 12 22 11 12 22 63 i min 25 22 63 i, min 11 12 22 25 63 void selection. Sort(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; } } }

Insertion Sort 63 25 12 22 11 25 63 12 22 11 12 25 63 22 11 12 22 25 63 11 11 12 22 25 63 insertion. Sort(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;

Merge Sort – Partition Process 35 62 33 20 5 72 48 50 35 62 33 20 35 62 5 33 20 5 5 72 48 50 72 72 48 50

Merge Sort – Merge Process 35 62 33 20 5 72 48 50
![[0] [1] [2] [3] [4] [5] [6] [7] 40 20 10 80 60 50 [0] [1] [2] [3] [4] [5] [6] [7] 40 20 10 80 60 50](http://slidetodoc.com/presentation_image/aa6e435eec24baf3d46228c978d55b5e/image-6.jpg)
[0] [1] [2] [3] [4] [5] [6] [7] 40 20 10 80 60 50 7 30 100 90 too. Big. Index Quicksort [8] [9] [10] 70 too. Small. Index Starting at the beginning of the array, we look for the first element that is greater than the pivot. (too. Big. Index) Starting from the other end we look for the first value that is less than or euqal to the pivot. (too. Small. Index) After finding the two out-of-place elements, exchange them. too. Big. Index++ too. Small. Index— Stop when too. Big. Index >= too. Small. Index
![[0] [1] [2] [3] [4] [5] [6] [7] 40 20 10 80 60 50 [0] [1] [2] [3] [4] [5] [6] [7] 40 20 10 80 60 50](http://slidetodoc.com/presentation_image/aa6e435eec24baf3d46228c978d55b5e/image-7.jpg)
[0] [1] [2] [3] [4] [5] [6] [7] 40 20 10 80 60 50 7 30 100 90 20 10 30 60 [9] [10] 70 too. Small. Index too. Big. Index 40 [8] 50 7 80 100 90 70 too. Big. Index too. Small. Index 40 20 10 30 7 50 60 too. Big. Index too. Small. Index 80 100 90 70

40 20 10 30 7 50 60 80 100 90 70 too. Small. Index too. Big. Index 7 20 10 30 40 50 60
![Heapsort 45 27 42 21 [0] 23 19 4 5 [1] [2] [3] [4] Heapsort 45 27 42 21 [0] 23 19 4 5 [1] [2] [3] [4]](http://slidetodoc.com/presentation_image/aa6e435eec24baf3d46228c978d55b5e/image-9.jpg)
Heapsort 45 27 42 21 [0] 23 19 4 5 [1] [2] [3] [4] 22 [5] 35 [6] [7] [8] [9]
![45 27 42 21 23 22 35 19 4 5 [0] [9] [1] [2] 45 27 42 21 23 22 35 19 4 5 [0] [9] [1] [2]](http://slidetodoc.com/presentation_image/aa6e435eec24baf3d46228c978d55b5e/image-10.jpg)
45 27 42 21 23 22 35 19 4 5 [0] [9] [1] [2] [3] [4] [5] [6] [7] [8] 5 27 42 21 23 22 35 19 4 45 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] 42 27 5 21 23 22 35 19 4 45 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] 42 27 35 21 23 22 5 19 4 45 [0] [1] [2] [3] [4] [5] [6] [7] • For an element in arr[i]: Parent[(i-1)/2] – Left child [2 i+1] – Right child [2 i+2] [8] [9]
![42 27 35 21 23 22 5 19 4 45 [0] [1] [2] [3] 42 27 35 21 23 22 5 19 4 45 [0] [1] [2] [3]](http://slidetodoc.com/presentation_image/aa6e435eec24baf3d46228c978d55b5e/image-11.jpg)
42 27 35 21 23 22 5 19 4 45 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] 4 27 35 21 23 22 5 19 42 45 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] 35 27 4 21 23 22 5 19 42 45 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] 35 27 22 21 23 4 5 19 42 45 [0] [6] [1] [2] [3] [4] [5] [7] • For an element in arr[i]: Parent[(i-1)/2] – Left child [2 i+1] – Right child [2 i+2] [8] [9]
![35 27 22 21 23 4 5 19 42 45 [0] [6] [1] [2] 35 27 22 21 23 4 5 19 42 45 [0] [6] [1] [2]](http://slidetodoc.com/presentation_image/aa6e435eec24baf3d46228c978d55b5e/image-12.jpg)
35 27 22 21 23 4 5 19 42 45 [0] [6] [1] [2] [3] [4] [5] [7] [8] [9] 19 27 22 21 23 4 5 35 42 45 [0] [6] [1] [2] [3] [4] [5] [7] [8] [9] 27 19 22 21 23 4 5 35 42 45 [0] [6] [1] [2] [3] [4] [5] [7] [8] [9] 27 23 22 21 19 4 5 35 42 45 [0] [6] [1] [2] [3] [4] [5] [7] • For an element in arr[i]: Parent[(i-1)/2] – Left child [2 i+1] – Right child [2 i+2] [8] [9]
![27 23 22 21 19 4 5 35 42 45 [0] [6] [1] [2] 27 23 22 21 19 4 5 35 42 45 [0] [6] [1] [2]](http://slidetodoc.com/presentation_image/aa6e435eec24baf3d46228c978d55b5e/image-13.jpg)
27 23 22 21 19 4 5 35 42 45 [0] [6] [1] [2] [3] [4] [5] [7] [8] [9] 5 23 22 21 19 4 27 35 42 45 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] 23 5 22 21 19 4 27 35 42 45 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] 23 21 22 5 19 4 27 35 42 45 [0] [1] [2] [3] [4] [5] [6] [7] • For an element in arr[i]: Parent[(i-1)/2] – Left child [2 i+1] – Right child [2 i+2] [8] [9]
![23 21 22 5 19 4 27 35 42 45 [0] [1] [2] [3] 23 21 22 5 19 4 27 35 42 45 [0] [1] [2] [3]](http://slidetodoc.com/presentation_image/aa6e435eec24baf3d46228c978d55b5e/image-14.jpg)
23 21 22 5 19 4 27 35 42 45 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] 4 21 22 5 19 23 27 35 42 45 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] 22 21 4 5 19 23 27 35 42 45 [0] [3] [1] [2] [4] [5] [6] [7] • For an element in arr[i]: Parent[(i-1)/2] – Left child [2 i+1] – Right child [2 i+2] [8] [9]
![22 21 4 5 19 23 27 35 42 45 [0] [3] [1] [2] 22 21 4 5 19 23 27 35 42 45 [0] [3] [1] [2]](http://slidetodoc.com/presentation_image/aa6e435eec24baf3d46228c978d55b5e/image-15.jpg)
22 21 4 5 19 23 27 35 42 45 [0] [3] [1] [2] [4] [5] [6] [7] [8] [9] 19 21 4 5 22 23 27 35 42 45 [0] [3] [1] [2] [4] [5] [6] [7] [8] [9] 21 19 4 5 22 23 27 35 42 45 [0] [3] [1] [2] [4] [5] [6] [7] • For an element in arr[i]: Parent[(i-1)/2] – Left child [2 i+1] – Right child [2 i+2] [8] [9]
![21 19 4 5 22 23 27 35 42 45 [0] [3] [1] [2] 21 19 4 5 22 23 27 35 42 45 [0] [3] [1] [2]](http://slidetodoc.com/presentation_image/aa6e435eec24baf3d46228c978d55b5e/image-16.jpg)
21 19 4 5 22 23 27 35 42 45 [0] [3] [1] [2] [4] [5] [6] [7] [8] [9] 5 19 4 21 22 23 27 35 42 45 [0] [1] 19 5 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] 4 21 22 23 27 35 42 45 [2] [3] [4] [5] [6] [7] • For an element in arr[i]: Parent[(i-1)/2] – Left child [2 i+1] – Right child [2 i+2] [8] [9]
![19 5 [0] 4 [0] [1] 4 21 22 23 27 35 42 45 19 5 [0] 4 [0] [1] 4 21 22 23 27 35 42 45](http://slidetodoc.com/presentation_image/aa6e435eec24baf3d46228c978d55b5e/image-17.jpg)
19 5 [0] 4 [0] [1] 4 21 22 23 27 35 42 45 [2] [3] [4] [5] [6] [7] [8] [9] 5 19 21 22 23 27 35 42 45 [1] [2] [3] [4] [5] [6] [7] • For an element in arr[i]: Parent[(i-1)/2] – Left child [2 i+1] – Right child [2 i+2] [8] [9]
- Slides: 17