GNOME_SORT(A[])
// assume index values 0 to n-1
- pos ← 1
- while pos < n do
- if A[pos] ≥ A[pos-1] then
- pos ← pos + 1
- else
- SWAP(A[pos],A[pos-1]
- if pos > 1 then
- pos ← pos -1
- return
- [1 point] Trace this algorithm for A = {2, 5, 4, 1}
- [2 points] What would be the best possible input for this algorithm? Why?
- [2 points] What would be the worst possible input for this algorithm? Why?
- [2 points] How does the algorithm work?
- [1 point] What is the natural measurement of the input size. The answer "n" is wrong.
- [2 points] Provide a timing function for the best case performance for this algorithm.
- [2 points] Simplify the timing function and provide the complexity class.