Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Lecture#03
Insertion Sort,
Bubble Sort,
Selection Sort
Lecture Contents
Slow Sorting Algorithms
Insertion Sort
Bubble Sort
Selection Sort
Sorting Algorithms …….. Insertion Sort
Say an array (to be sorted) has N elements
We split array into two parts; first part contains sorted elements while
second part contains elements that are not sorted yet
Initially the sorted part contains only one element (as it is sorted obviously)
while second part contains N-1 elements
6 4 3 22 98 35 34 18 11 65
4 6 3 22 98 35 34 18 11 65
3 4 6 22 98 35 34 18 11 65
3 4 6 11 18 22 34 35 65 98
Sorting Algorithms …….. Insertion Sort
33 10 20 12 8
n=5
i=2
key = 10
j=1
A[j] = 33
n |a| 1
for i 2 to n do n times
https://www.youtube.com/watch?v=lx9G71uLXIg
2. Insertion Sort
https://www.youtube.com/watch?v=DFG-XuyPYUQ
https://www.youtube.com/watch?v=TwGb6ohsvUU
3. Bubble Sort
https://www.youtube.com/watch?v=Ui97-_n5xjo
https://www.youtube.com/watch?v=Ui97-_n5xjo