Question: Read the pseudocode below for a sorting algorithm as well as the ( incorrect ) proof claiming that the algorithm has expected running time E

Read the pseudocode below for a sorting algorithm as well as the (incorrect) proof claiming that the algorithm has expected running time
E[T(n)]= O(n log(n)).
Identify and describe the error with the proof.
Sort(A):
if len(A)<=1:
return
# Pick the pivot x
x =0
if random.choice([True, False]):
x = max(A)
else:
x = min(A)
L, R = Partition(A, x)
A = L +[x]+ R
Sort(L)
Sort(R)
Partition(A, x):
L =[]
R =[]
for element in A:
if element < x:
L.append(element)
elif element > x:
R.append(element)
return L, R
# Initial call
A =[some array of elements]
Sort(A)
Claim: The algorithm runs in time T(n)= O(n log(n)).
Proof: At the top level, we split the array by choosing a pivot x and partitioning the array into two parts, L and R. Choosing the pivot and partitioning the array each take O(n) time. At each subsequent level, we increase the number of subproblems by a constant factor (2), and the subproblems only become smaller. Therefore, the running time per level can only increase by a constant factor. By induction, since for the first level it is O(n), it will be O(n) for all levels. There are O(log n) levels, so in total, the running time is T(n)= O(n log n). [We are expecting: A clear and concise description, in plain English, of the error with this proof.]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!