Answered step by step
Verified Expert Solution
Link Copied!

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 Alg1 described below in pseudo-code. Alg1 takes as input an array (whose elements are either 0 or 1) and an integer (the size of the array). The index of the first element of the array is 1.
Alg1(A,n)
2.
num1 larr0
num 0larr0
ilarr1
6.
while in do
if A[i]=1 then
num1 larr num1+1
if num1n2 then
return TRUE
endif
else
num 0larr num 0+1
if num0>n2 then
return FALSE
endif
endif
ilarri+1
endfor
When estimating the run-time complexity of Alg1 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 8 of Alg1.)
1. State the best-case running time complexity of Alg1 as a function of the size of
the input array. Do not use the asymptotic notation. Explain your answer (show your
calculations).
2.State the worst - case running time complexity of Alg1 as a function of the size of
the input array. Do not use the asymptotic notation. Explain your answer (show your
calculations).
3.State the average case complexity of Alg1 as a function of the size of the input
array. Explain your answer using the methodology presented in class, i.e., define an appropriate sample space, state a probability distribution function (assume a uniform distribution), define the necessary random variables, etc. Show your calculations.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions