Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started