1 / 24

Sorting Animation Chapter 10

Sorting Animation Chapter 10. Selection Sort. Another way of sorting is the selection sort The main idea is to keep finding the smallest (and next smallest) items in the array And move them into correct position (swap). Selection Sort. data. small_pos. smallest. n. 0. 45. 0. k.

nigel-white
Download Presentation

Sorting Animation Chapter 10

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. Sorting AnimationChapter 10

  2. Selection Sort • Another way of sorting is the selection sort • The main idea is to keep finding the smallest (and next smallest) items in the array • And move them into correct position (swap)

  3. Selection Sort data small_pos smallest n 0 45 0 k 45 < smallest? F 0

  4. Selection Sort data small_pos smallest n 0 45 1 k 32 < smallest? T 0

  5. Selection Sort data small_pos smallest n 1 32 1 k 32 < smallest? T 0

  6. Selection Sort data small_pos smallest n 1 32 2 k 56 < smallest? F 0

  7. Selection Sort data small_pos smallest n 1 32 3 k 9 < smallest? T 0

  8. Selection Sort data small_pos smallest n 3 9 3 k 9 < smallest? T 0

  9. Selection Sort data small_pos smallest n 3 9 4 k 21 < smallest? F 0

  10. Selection Sort data small_pos smallest n 3 9 5 k 77 < smallest? F 0

  11. Selection Sort data small_pos smallest n 3 9 6 k 17 < smallest? F 0

  12. Selection Sort—SWAP! data small_pos smallest n 3 9 6 k Swap(data[k], data[small_pos]); 0

  13. Selection Sort data small_pos smallest n 1 32 1 k 32 < smallest? F 1

  14. Selection Sort data small_pos smallest n 1 32 2 k 32 < smallest? F 1

  15. Selection Sort data small_pos smallest n 1 32 3 k 45 < smallest? F 1

  16. Selection Sort data small_pos smallest n 1 32 4 k 21 < smallest? T 1

  17. Selection Sort data small_pos smallest n 4 21 4 k 21 < smallest? T 1

  18. Selection Sort data small_pos smallest n 4 21 5 k 77 < smallest? F 1

  19. Selection Sort data small_pos smallest n 4 21 6 k 18 < smallest? T 1

  20. Selection Sort data small_pos smallest n 6 18 6 k 18 < smallest? T 1

  21. Selection Sort data small_pos smallest n 6 18 7 k 17 < smallest? T 1

  22. Selection Sort data small_pos smallest n 7 17 7 k 17 < smallest? T 1

  23. Selection Sort—SWAP! data small_pos smallest n 7 17 7 k Swap(data[k], data[small_pos]); 1

  24. Selection Sort—and so on data small_pos smallest n 2 56 2 k 56 < smallest? F 2

More Related