An Example: Insertion Sort
InsertionSort(A, n) {for i = 2 to n { key = A[i] j = i - 1; while (j > 0) and (A[j] > key) { A[j+1] = A[j] j = j - 1 } A[j+1] = key}
}
10
30
40
40
1
2
3
4
i = 4 j = 2 key = 20A[j] = 30 A[j+1] = 40
Previous slide
Next slide
Back to first slide
View graphic version