1 / 17

Bubble Sort Example

Bubble Sort Example. Selection Sort. i.

junewall
Download Presentation

Bubble Sort Example

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Bubble Sort Example

  2. 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

  3. 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;

  4. Merge Sort – Partition Process

  5. Merge Sort – Merge Process

  6. 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

  7. tooSmallIndex tooBigIndex tooBigIndex tooSmallIndex tooBigIndex tooSmallIndex

  8. tooSmallIndex tooBigIndex

  9. Heapsort 45 27 42 21 23 22 35 19 4 5

  10. For an element in arr[i]: Parent[(i-1)/2] • Left child [2i+1] • Right child [2i+2]

  11. For an element in arr[i]: Parent[(i-1)/2] • Left child [2i+1] • Right child [2i+2]

  12. For an element in arr[i]: Parent[(i-1)/2] • Left child [2i+1] • Right child [2i+2]

  13. For an element in arr[i]: Parent[(i-1)/2] • Left child [2i+1] • Right child [2i+2]

  14. For an element in arr[i]: Parent[(i-1)/2] • Left child [2i+1] • Right child [2i+2]

  15. For an element in arr[i]: Parent[(i-1)/2] • Left child [2i+1] • Right child [2i+2]

  16. For an element in arr[i]: Parent[(i-1)/2] • Left child [2i+1] • Right child [2i+2]

  17. For an element in arr[i]: Parent[(i-1)/2] • Left child [2i+1] • Right child [2i+2]

More Related