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
ETn On logn
Identify anddescribe the error with the proof.
SortA:
if lenA:
return
# Pick the pivot x
x
if random.choiceTrue False:
x maxA
else:
x minA
L R PartitionA x
A L x R
SortL
SortR
PartitionA x:
L
R
for element in A:
if element x:
Lappendelement
elif element x:
Rappendelement
return L R
# Initial call
A some array of elements
SortA
Claim: The algorithm runs in time Tn On logn
Proof: At the top level, we split the array by choosing a pivot x and partitioning the arrayinto two parts, L and R Choosing the pivot and partitioning the array each take On time. Ateach subsequent level, we increase the number of subproblems by a constant factor and thesubproblems only become smaller. Therefore, the running time per level can only increase by aconstant factor. By induction, since for the first level it is On it will be On for all levels. Thereare Olog n levels, so in total, the running time is Tn On log nWe 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
