Question: Consider the algorithm Alg 1 described below in pseudo - code. Alg 1 takes as input an array ( whose elements are either 0 or
Consider the algorithm Alg described below in pseudocode. Alg takes as input an array whose elements are either or and an integer the size of the array The index of the first element of the array is
Alg
num larr
num larr
ilarr
while do
if then
num larr num
if num then
return TRUE
endif
else
num larr num
if num then
return FALSE
endif
endif
ilarri
endfor
When estimating the runtime complexity of Alg as a function of the size of the input array consider only the number of array comparisons performed when the algorithm is run on the input array. Note that array comparisons only occur on line of Alg
State the bestcase running time complexity of Alg as a function of the size of
the input array. Do not use the asymptotic notation. Explain your answer show your
calculations
State the worst case running time complexity of Alg as a function of the size of
the input array. Do not use the asymptotic notation. Explain your answer show your
calculations
State the average case complexity of Alg as a function of the size of the input
array. Explain your answer using the methodology presented in class, ie define an appropriate sample space, state a probability distribution function assume a uniform distribution define the necessary random variables, etc. Show your calculations.
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
