You are on page 1of 1

Palestine Polytechnic University

College of Information Technology and Computer Engineering


Algorithms / Spring 2022-2023 / Quiz 1 - Section Su Tu Th 9:00-9:50
Student Name: …………….…………...…..…….....ID:……..……..…… Time: 15 Minutes Date 26/2/2023

Question 1: For the following code,

for (i=1;i<=n;i=i+1)
for (j=n;j>=√𝑛;j=j-1)
c++;

(a) How many times c++ is executed if n=4? …………12…………..

(b) What is the exact time complexity? ………𝒏𝟐 − 𝒏√𝒏 + 𝒏 ………..

√𝑛 𝑛

∑ ∑ 1 = 𝑛(𝑛 − √𝑛 + 1) = 𝑛2 − 𝑛√𝑛 + 𝑛
𝑖=1 𝑗=√𝑛

Question 2: In each of the following situations, indicate whether f = O(g), or f = Ω(g), or both (in
which case f = Θ(g)). Justify your answers.

(a) f(n) = 2n , g(n) = n2n-1

Since lim is 0, f(n)=O(g(n)).

𝑛 √𝑛
(b) f(n) = , g(n) = √𝑛 (𝑙𝑜𝑔 𝑛)2
log 𝑛

Since lim is ∞, f(n)=Ω(g(n)).

Good Luck

You might also like