5. Consider the following algorithm:
1 Function helper (L, i, j):
/* L is a list of n positive integers, starting at index 0, 0 ≤ i, j < n
x := L[i]
2
3
L[i]:= L[j]
4
L[j] := x
5 Function mystery (L,n):
/* L is a list of n positive integers, starting at index 0
i:=n-1
6
7
while i > 0 do
8
x := 0
9
for j:= 0 to i do
10
if L[j] > L[x] then
11
x := j
12
helper (L, i, x)
13
i:=i-1
/*
/*
(a) (5 points) Explain what mystery does and how it works at a high level in plain English.
(b) (5 points) Does this algorithm have asymptotically different performance in its best and worst
cases?
If yes, explain what each case is and tightly bound its runtime.
If no, say if it would be possible to tweak this algorithm (without making it a fundamentally different
algorithm or asymptotically slower) so it had an asymptotically faster runtime in the best case. If
possible, explain how. If impossible, explain why.