0% found this document useful (0 votes)
4 views2 pages

CS2002 - Data Structures and Algorithms: Quiz 1 (Paper A)

The document contains two quizzes for a CS2002 course on Data Structures and Algorithms, each with three questions focused on analyzing algorithm efficiency in terms of time and space complexity. The quizzes require students to arrange functions by growth rate, compute complexities for recursive and iterative algorithms, and analyze provided code snippets for their big-oh notation. Each quiz has a maximum of 10 marks and is timed for 15 minutes.

Uploaded by

f236087
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

CS2002 - Data Structures and Algorithms: Quiz 1 (Paper A)

The document contains two quizzes for a CS2002 course on Data Structures and Algorithms, each with three questions focused on analyzing algorithm efficiency in terms of time and space complexity. The quizzes require students to arrange functions by growth rate, compute complexities for recursive and iterative algorithms, and analyze provided code snippets for their big-oh notation. Each quiz has a maximum of 10 marks and is timed for 15 minutes.

Uploaded by

f236087
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Name: _________________________ Section: BEE-4C Student ID: ______________

CS2002 – Data Structures and Algorithms


Quiz 1 (Paper A)
Spring 2025

Maximum Marks: 10 6 February 2025 Time Allowed: 15 minutes


The use of mobile phones and other helping material is not allowed

Taxonomy
CLO No. CLO Statement Domain
Level
Compute the efficiency of algorithms and data structures in
1 Cognitive 3
terms of time and space complexity.

Question Number 1 (CLO 1) (2 marks)


Use the growth rate concept to arrange the following functions in ascending order. Also discuss which
functions grow at the same rate.
𝑁, 𝑁 log 𝑁 , 𝑁 log log 𝑁 , 𝑁log 2 𝑁, 2𝑁 , 37, 𝑁 3

The ascending order of growth rate is given below.


37, 𝑁, 𝑁 log log 𝑁 , 𝑁 log 𝑁 , 𝑁log 2 𝑁, 𝑁3, 2𝑁
None of the above grow at the same rate.

Question Number 2 (CLO 1) (3 marks)


Compute the time and space complexity of a recursive algorithm that returns the sum of all the
elements of a 1D array of size N.
There will be N recursive calls in this case, and every recursive call shall have its own memory.
Hence,
Time Complexity is O (N)
Space Complexity is also O(N)

Question Number 3 (CLO 1) (5 marks)


Analyze the following program to find the time complexity in big-oh notation. Justify your answer
with proper reason(s)/calculation(s).
void function(int n)
{
int count = 0;
for (int i = n/2; i <= n; i++)
for (int j = 1; j+n/2 <= n; j++)
for (int k = 1; k <= n; k = k * 2)
count++;
}
• In inner most loop, the k is multiplied by 2 in every iteration, hence its complexity is log2n
• For the loop with variable j, there are n/2 maximum iterations, hence its complexity is n/2
• For outermost loop, there are n/2 iterations, and its complexity is n/2
• All the loops are nested, hence total complexity is O((log2n)(n/2)(n/2)) = O(n2log2n)
Name: _________________________ Section: BEE-4C Student ID: ______________

CS2002 – Data Structures and Algorithms


Quiz 1 (Paper B)
Spring 2025

Maximum Marks: 10 6 February 2025 Time Allowed: 15 minutes


The use of mobile phones and other helping material is not allowed

Taxonomy
CLO No. CLO Statement Domain
Level
Compute the efficiency of algorithms and data structures in
1 Cognitive 3
terms of time and space complexity.

Question Number 1 (CLO 1) (2 marks)


Use the growth rate concept to arrange the following functions in ascending order. Also discuss which
functions grow at the same rate.
√𝑁, 𝑁 2 , 𝑁log 2 𝑁, 𝑁 log(𝑁 2 ), 1000, 𝑁 2 log 𝑁 , 𝑁 4

The ascending order of growth rate is given below.


1000, √𝑁, 𝑁 log(𝑁 2 ), 𝑁log 2 𝑁, 𝑁2 , 𝑁 2 log 𝑁 , 𝑁4
None of the above grow at the same rate.

Question Number 2 (CLO 1) (3 marks)


Compute the time and space complexity of an iterative algorithm that returns the sum of all the
elements of a 1D array of size N.
To find the sum of all the array elements, we need at least N iterations, hence,
Time complexity is O(N)
There is no additional space required for iterative implementation, hence,
Space Complexity is O(1)

Question Number 3 (CLO 1) (5 marks)


Analyze the following program to find the time complexity in big-oh notation. Justify your answer
with proper reason(s)/calculation(s).
sum = 0;
for(int i = 1; i < n; i+=2)
for(int j = 1; j < i*i; j++)
if(j % i == 0)
for(int k = 1; k < j; k*=2)
sum++;
• For the outer most loop the complexity is n/2 as there is an increment of 2 after every
iteration.
• For inner loop, there are n2 iterations, as j can go up to i2 and i = n. Its complexity is n2.
• The inner most loop will execute if the condition is true. And the condition can be true for a
maximum of √𝑛2 time. Hence its complexity is n, but k is multiplied by 2 after every
iteration, hence the actual complexity of inner loop is log2n.
• Total complexity = O((n/2)(n2)(log2n)) = O(0.5n3log2n) = O(n3log2n)

You might also like