資料結構›Ch7 搜尋與排序第 42 題/共 76 題
42. Insertion Sort、Pseudocode
#DS-07-042易Insertion SortPseudocode
(4%) Initially, array X[] = {n, 2, 3, 4, 5, …, n-1, n}, n >= 4. The array index is zero-based. Insertion sort is used to sort the elements of X in descending order. Given the following pseudo code, how many times is Line L performed?
j = 1
while j < n
b = X[j]
k = j - 1
while k >= 0 and X[k] < b
X[k+1] = X[k] // Line L
k = k - 1
end while
X[k+1] = b
j = j + 1
end while
📄 交大112
▤完整推導請見《WH 資工筆記 · 資料結構》Ch7 搜尋與排序