More Related Content Similar to Computer notes - Sorting (20) More from ecomputernotes (20) Computer notes - Sorting1. Class No.38 Data Structures http://ecomputernotes.com 3. Sorting Integers 20 8 5 10 7 5 7 8 10 20 How to sort the integers in this array? http://ecomputernotes.com 6. Selection Sort -- Example 19 12 7 5 http://ecomputernotes.com 1 2 3 0 7 12 19 5 a: 1 2 3 0 7 19 12 5 a: 1 2 3 0 19 7 12 5 a: 1 2 3 0 7 12 19 5 a: 1 2 3 0 5 7 12 19 a: a: 1 2 3 0 12. Insertion Sort -- Example http://ecomputernotes.com 1 2 3 0 12 5 7 19 a : 1 2 3 0 19 5 7 12 a : 1 2 3 0 12 19 7 5 a : 1 2 3 0 7 12 19 5 a : 14. Insertion Sort -- animation count val pos 1 12 0 1 12 -1 19 12 http://ecomputernotes.com 1 2 3 0 12 5 7 19 a : 1 2 3 0 19 5 7 19 a : 1 2 3 0 5 7 19 a : 12 1 2 3 0 19 5 7 12 a : 15. Insertion Sort -- animation (cont) count val pos 2 5 1 2 5 -1 19 12 2 5 0 5 http://ecomputernotes.com 1 2 3 0 12 19 7 5 a : 1 2 3 0 19 5 7 12 a : 1 2 3 0 5 7 12 a : 19 1 2 3 0 19 7 12 a : 19 1 2 3 0 12 19 7 12 a : 16. Insertion Sort -- animation (cont) count val pos 3 7 2 3 7 0 3 7 1 19 12 7 http://ecomputernotes.com 1 2 3 0 12 19 7 5 a : 1 2 3 0 12 19 7 5 a : 1 2 3 0 12 19 19 5 a : 1 2 3 0 12 12 19 5 a : 1 2 3 0 7 12 19 5 a : 19. Bubble Sort -- Example a: http://ecomputernotes.com 1 2 3 0 12 7 19 5 a: 1 2 3 0 12 7 19 5 a: 19 12 7 5 1 2 3 0 a: 12 19 7 5 a: 1 2 3 0 5 12 7 19 1 2 3 0 a: 1 2 3 0 12 7 19 5 a: 1 2 3 0 7 12 19 5 a: 1 2 3 0 7 12 19 5 a: 1 2 3 0 7 12 19 5 a: 1 2 3 0 7 12 19 5 a: 24. Divide and Conquer What if we split the list into two parts? 10 12 8 4 2 11 7 5 http://ecomputernotes.com 10 12 8 4 2 11 7 5 25. Divide and Conquer Sort the two parts: http://ecomputernotes.com 10 12 8 4 2 11 7 5 4 8 10 12 2 5 7 11 26. Divide and Conquer Then merge the two parts together: http://ecomputernotes.com 4 8 10 12 2 5 7 11 2 4 5 7 8 10 11 12 Editor's Notes End of lecture 43. Start of 44 End of lecture 44.