Algorithms
Algorithms
Question Bank
1. Illustrate the different stages involved in algorithm construction and analysis with a
diagram.
2. Define algorithm. Explain asymptotic notations Big Oh, Big Omega, and Big Theta
3. If t1(n) ∈ O(g1(n)) and t2(n) ∈ O(g2(n)), then show that t1(n) + t2(n) ∈
notations.
O(max{g1(n), g2(n)})
4. Explain the general plan for analyzing the efficiency of a recursive algorithm. Suggest
a recursive algorithm for a tower of Hanoi problem. Derive its efficiency.
5. Explain the general plan for analyzing the efficiency of a non-recursive algorithm.
Suggest a non-recursive algorithm to find the maximum element in the list of n
numbers. Derive its efficiency.
6. Explain with an algorithm to derive the worst-case efficiency for Bubble sort.
7. Explain the concept of divide and conquer. Design an algorithm for merge sort and
derive its time complexity.
8. Explain Strassen’s matrix multiplication and derive its time complexity.
9. Construct sequential search algorithm and analyze its time efficiency.
10. Construct Brute force pattern matching algorithm and analyze its time efficiency.
11. Explain Strassen’s Matrix Multiplication and analyze its time efficiency.
S←S+i∗i
for i ← 1 to n do
return S
What does this algorithm compute?
What is its basic operation?
How many times is the basic operation executed?
What is the efficiency class of this algorithm?
Suggest an improvement, or a better algorithm altogether, and indicate its
efficiency class. If you cannot do it, try to prove that, in fact, it cannot be
done.
8. Consider the following algorithm.
ALGORITHM Secret(A[0..n − 1])
//Input: An array A[0..n − 1] of n real numbers
minval ← A[0];
maxval ← A[0]
for i ← 1 to n − 1 do
if A[i] < minval
minval ← A[i]
if A[i] > maxval
maxval ← A[i]
return maxval – minval
Set up and solve a recurrence relation for the number of times the algorithm’s basic
operation is executed.
How does this algorithm compare with the straightforward non-recursive algorithm
for computing this sum?
11. Consider the following recursive algorithm.
ALGORITHM Q(n)
//Input: A positive integer n
if n = 1
Set up a recurrence relation for this function’s values and solve it to determine what
this algorithm computes.
Set up a recurrence relation for the number of multiplications made by this algorithm
and solve it.
Set up a recurrence relation for the number of additions/subtractions made by this
algorithm and solve it.
12. A network topology specifies how computers, printers, and other devices are connected
over a network. The figure below illustrates three common topologies of networks: the ring,
the star, and the fully connected mesh.
You are given a boolean matrix A[0..n − 1, 0..n − 1], where n > 3, which is supposed to be
the adjacency matrix of a graph modeling a network with one of these topologies. Your task
is to determine which of these three topologies, if any, the matrix represents. Design a brute-
force algorithm for this task and indicate its time efficiency class.
13. Apply the DFS-based algorithm to solve the topological sorting problem for the following
digraphs:
14. Design Merge Sort Algorithm and analyze its time efficiency. Apply Merge sort on these
elements. 25,75,40,10,20,05,15.
15. Design Qucik Sort Algorithm and analyze its time efficiency. Apply Quick sort on these
elements. 25,75,40,10,20,05,15.