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

CNG315 Lecture2 InclassExercises

The document contains in-class exercises for an algorithms course at Middle East Technical University, focusing on algorithm growth rates, asymptotic notation, and the analysis of the Merge Sort algorithm. It includes tasks such as ordering functions by growth rate, calculating running time for specific input sizes, determining computational complexity of code snippets, identifying dominant terms and their Big-Oh complexities, evaluating true/false statements about expressions, and sorting a list using Merge Sort. References for additional reading are also provided.

Uploaded by

salaramir2002
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)
20 views2 pages

CNG315 Lecture2 InclassExercises

The document contains in-class exercises for an algorithms course at Middle East Technical University, focusing on algorithm growth rates, asymptotic notation, and the analysis of the Merge Sort algorithm. It includes tasks such as ordering functions by growth rate, calculating running time for specific input sizes, determining computational complexity of code snippets, identifying dominant terms and their Big-Oh complexities, evaluating true/false statements about expressions, and sorting a list using Merge Sort. References for additional reading are also provided.

Uploaded by

salaramir2002
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

MIDDLE EAST TECHNICAL UNIVERSITY, NORTHERN CYPRUS CAMPUS

CNG315 Algorithms – In-class Exercises for Lecture 2

Topics: Algorithm Growth Rates, Common Growth Rates, Asymptotic Notation: Big-Theta, Big-O and Big-
Omega, Merge Sort Algorithm Analysis with Recursion Tree.

1. Order the following functions by growth rate: n, n2,logn, nlogn, sqrt(n), 2n, 7, n3

2. An algorithm takes 2 ms for input size 256. How long will it take for input size 1024 if the running
time is O (log n)?

3. Work out the computational complexity of the following pieces of code:

a. for( int i = 0; i < n; ++i ) {


for( int j = 0; j < n * n; ++j ) {
... // constant number of operations
}
}

b. for( int i = n; i > 0; i /= 2 ) {


for( int j = 1; j < n; j *= 2 ) {
for( int k = 0; k < n; k += 2 ) {
... // constant number of operations
}
}
}

4. Assume that each of the expressions below gives the processing time T(n) spent by an algorithm for
solving a problem of size n. Select the dominant term(s) having the steepest increase in n and
specify the lowest Big-Oh complexity of each algorithm.

Expression Dominant term(s) O(…)


5 + 0.001n3 + 0.025n

500n + 100n1.5 + 50n log2n

0.3n + 5n1.5 + 2.5n1.75

n2log2n + n(log2 n)2

0.01n + 100n2

2n + n0.5 + 0.5n1.25

0.01n log2 n + n(log2 n)2

Page 1 of 2
5. Are each of the following true or false?

Expression True False


3n2 + 10 n log n = O(n log n)

3n2 + 10 n log n = Omega(n2)

3n2 + 10 n log n = Theta(n2)

n log n + n/2 = O(n)

10 SQRT(n) + log n = O(n)

SQRT(n) + log n = O(log n)

SQRT(n) + log n = Theta(log n)

SQRT(n) + log n = Theta(n)

2 SQRT(n) + log n = Theta(SQRT(n))

SQRT(n) + log n = Omega(1)

SQRT(n) + log n = Omega(log n)

SQRT(n) + log n = Omega(n)

6. Sort 4, 2, 5, 2, 6, 9 using Merge Sort

References:
 https://www.cs.auckland.ac.nz/courses/compsci220s1t/lectures/lecturenotes/GG-
lectures/220exercises1.pdf
 https://www.cse.wustl.edu/~sg/CS241_FL99/hw1-practice.html

Page 2 of 2

You might also like