Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

TE/ME

Problem Set 2
CS101

May 2016

Question1:
a. Give the Big O of the following function.

b. What does this function do?


c. How does this function works in best case scenario?
d. How does this function works in worst case scenario?
(Hint: Big O is the function for time complexity giving upper bound for
the time taken by your function in worst case scenario.)
Question 2:
a. How will you perform same operation as question 2 using single for
loop?
b. What is the Big O of your implementation?
Question3:
Give example algorithms against the following types.
a.
b.
c.
d.
e.

Greedy
Brute
Binary Trees
Random
Divide and Conquer

Question4:
Give difference between recursive and iterative functions.
Computer Science & Engineering Department, UET Lahore

Sahar Waqar/Samyan Qayyum Wahla

Question5:
Give iterative and recursive implementation of the following.
a. Factorial
b. Summation of series up to n. (1 + 2 + 3 + . + n)
Question6:
Define following.
a. Worst case of algorithm
b. Best case of algorithm
c. Average case of algorithm.
Question7:
How algorithms will help you in your respective engineering practices?
Question8:
Given a bracket sequence, S containing {,[,(,},],) etc. all known brackets.
Devise an algorithm to check if it is a valid sequence i.e. all opening
brackets must have a closing match.
Lets say,
If input => S = {{, (,),}} => output = valid.
If input => S = {{, {,[,]} => output = invalid.
If input => S = {} => output = valid.
If input => S = {{, {,},}} => output = valid.
.
Etc.

Computer Science & Engineering Department, UET Lahore

Sahar Waqar/Samyan Qayyum Wahla

You might also like