191ai521 Daa QB1
191ai521 Daa QB1
191ai521 Daa QB1
QUESTION BANK
UNIT-I INTRODUCTION
29 In algorithm visualization of bubble sort algorithm the non-linear curve of the CO1.9 CL1
sorted elements is close to .
A.3n
B.n^3
C.2n
D.n^2
30 The upper bound on the time complexity of then on deterministic sorting CO1.9 CL1
algorithm is
A.O(n)
B.O(n logn)
C.O(n^2)
D.O(log n)
PART – B FOUR MARK QUESTIONS
1 Prove the equality gcd(m,n) =gcd(n, m mod n) for every pair of positive integers CO1.1 CL3
m and n using consecutive integer checking algorithm.
2 Understand the Euclid’s treatise, which uses subtractions rather than integer CO1.1 CL3
divisions. Write a pseudocode for this version of Euclid’s algorithm.
3 Describe the standard algorithm for finding the binary representation of a positive CO1.2 CL3
decimal integer.
a.in English.
b.in a pseudocode.
4 Consider matrix multiplication. Given two n × n matrices A and B, find the CO1.2 CL4
time efficiency of the definition-based algorithm for computing their product C =
AB. By definition, C is an n × n matrix whose elements are computed as the
scalar (dot) products of the rows of matrix A and the columns of matrix B.
where C[i, j ]= A[i, 0]B[0, j]+ . . . + A[i, k]B[k, j]+ . . . + A[i, n − 1]B[n − 1, j]
for every pair of indices 0 ≤ i, j ≤ n − 1.
5 Consider the algorithm for the sorting problem that sorts an array by counting, CO1.3 CL3
for each of its elements, the number of smaller elements and then uses this
information to put the element in its appropriate position in the sorted array:
8 Use the informal definition of O, Θ, and Ω to determine whether the following CO1.5 CL4
assertions are true or false.
a. n(n+1)/2∈O(n3) b. n(n+1)/2∈O(n2) c. n(n+1)/2∈Θ(n3)
d. n(n+1)/2∈Ω(n)
9 Could you describe the methodology or approach used within each component of CO1.6 CL2
the framework?
10 Consider the following well-known sorting algorithm (we shall study it more CO1.7 CL3
closely later in the book) with a counter inserted to count the number of key
comparisons.
Algorithm SortAnalysis(A[0..n−1])
//Input: An arrayA[0..n −1]of n or durable elements
//Output: The total number of key comparisons made
count←0
fori←1ton−1do
v← A[i]j←i−1
while j≥ 0 and A[j] > v do count←count+ 1
A[j+1]←A[j]
j←j−1
A[j+1]←v
Is the comparison counter inserted in the right place? If you believe It is, prove it;
if you believe it is not, make an appropriate correction.
11 Consider the element uniqueness problem; check whether all the elements in a CO1.8 CL3
given array of n elements are distinct using straight forward algorithm.
12 Compute the factorial function F(n)=n! for an arbitrary non negative integer n. CO1.8 CL4
Since n!=1….(n-1)*n=(n-1)!*n for n>=1 and 0!=1, using recursive algorithm.
13 Give an algorithm to check whether all the Elements in a given array of n CO1.9 CL2
elements are distinct. Find the worst case complexity of the same
PART – C
1 a. Among all inputs with 1=m, n=10, how many divisions did the Euclid CO1.1
algorithm make in the shortest amount of steps? CL3
b. Estimate how many times faster it will be to find gcd(31415, 14142) by
Euclid’s algorithm compared with the algorithm based on checking consecutive
integers from min{m, n} down to gcd(m, n).
2 Write a pseudocode for an algorithm for finding real roots of equation ax2 + bx + CO1.2
c = 0 for arbitrary real coefficients a, b, and c. (You may assume the availability CL4
of the square root function sqrt(x).)
3 (i) Explain how analysis of linear search is done with a suitable CO1.3 CL4
illustration.
(ii) Define recurrence equation and explain how solving recurrence
equations are done.
4 For each of the following algorithms, indicate CO1.4 CL4
(i)a natural size metric for its inputs;
(ii)its basic operation;
(iii)whether the basic operation count can be different for inputs of the same
size;
a) Computing the sum of n numbers
b) Computing n!
c) Finding the large set of n numbers
d) Euclid’s algorithm
e) Sieve of Eratosthenes
f) Pen-and-pencil algorithm for multiplying two n-digit decimal integers
5 Use the most appropriate notation among Big-Oh, Theta, Big-Omega to indicate CO1.5
the time efficiency class of sequential search CL2
a) in the worst case(4m)
b) in the best case(4m)
c) in the average case(4m)
6 (i) Briefly explain the mathematical analysis of recursive and non- CO1.6
recursive algorithm.
(ii) Give the general plan for analyzing the time efficiency of recursive algorithm
and use recurrence to find number of moves Towers of Hanoi problem.
7 Consider the problem of finding the value of the largest element in a list of n CO1.8
numbers. CL3
a)Write an algorithm
b)List out the general plan for analyzing the time efficiency of non recursive
algorithm.
8 CO1.8
Give the recursive algorithm which finds the number of binary digits in the CL2
binary representation of a positive decimal integer. Find the recurrence relation
and complexity.
UNIT II
BRUTE FORCE AND DIVIDE-AND-CONQUER
a) 4 b) 5 c)8 d) 9
28 In what time can a binary heap be built? CO2.8 CL2
a)O(N) b)O(Nlog N) c)O(logN) d)O(N2)
29 What does the following diagram depict? CO2.9 CL2
2 Design a brute-force algorithm for computing the value of a polynomial CO 2.1 CL2
p(x) = anxn + an-1 xn-1 + ... +a1x + a0 at a given point x0 and determine its
worst-case efficiency class.
3 Find the number of comparisons made by the sentinel version of sequential CO 2.1 CL2
search a. in the worst case. b. in the average case if the probability of a
successful search is p (0 ≤ p ≤ 1).
4 Find the pattern NOT in the following string NOBODY NOTICED HIM by CO2.2 CL3
using brute force string matching algorithm
5 Examine a brute force algorithm for string matching problem. CO2.2 CL3
Pattern: abaa;
Searched String: ababbaabaaab
6 Is it possible to compute the distance between the two closest points using CO2.3 CL1
brute force approach? Justify your answer with pseudocode.
7 Assuming that each tour can be generated in constant time, what will be the CO2.4 CL2
efficiency class of the exhaustive search algorithm outlined in the text for
the travelling salesman problem?
8 Generate the actions of shortest paths for the given graph from vertex1 to CO2.5 CL4
all remaining vertices using Brute force approach.
1->2=20, 2->1=2, 1->3=15, 2->5=10, 2->6=30, 3->6=10, 3->4=4, 5-
>4=15, 6->4=4, 6->5=10.
9 Find the shortest distance between the vertices using travelling salesman CO2.6 CL4
problem.
10 State the brute force Knapsack. Find an optimal solution to the Knapsack CO2.7 CL3
instance n=4, m=16, (v1,v2,v3,v4) =(20,30,50,10) and (W1,W2,W3,W4)=
(2,5,10,5).
11 Apply merge sort for the following elements 8, 3, 2, 9, 7, 1, 5, 4. CO2.8 CL3
12 Multiply the numbers 54 and 45. Evaluate by using multiplication CO2.9 CL3
of Large integer concepts.
PART – C
1 Sort the array value 89,45,68,90,29,34,17 using bubble sort and analyze its CO2.1 CL2
time complexity.
2 Derive an algorithm to find the key element of 39 in an array CO2.2 CL2
13,9,21,15,39,19,27 using sequential search and find out the time
complexity for best, worst and average cases.
3 Consider the following example of an unsorted array that we will sort CO2.3 CL3
with the help of the selection sort using brute force approach. And
compute the time complexity A[]=(7,4,3,6,5).
4 Evaluate the shortest path using travelling salesman problem in CO2.4 CL3
brute force approach.
5 Find and analyze the optimal solution for the assignment problem C02.6 CL4
using brute force for the given below
Job/person J1 J2 J3 J4
P1 9 2 7 8
P2 6 4 3 7
P3 5 8 1 8
P4 7 6 9 4
6 Perform binary search on list of elements 5,7,9,13,32,33,42,54,56,88 and CO2.7 CL2
find the key element is 33 using divide and conquer, and also estimate the
time complexity.
7 Design an algorithm for finding pivot element in quick sort algorithm using CO2.8 CL3
the elements 5, 3, 1, 9, 8,2, 47 and analyze its time complexity.
8 Multiply the following two matrices by Strassen’s matrix multiplication CO2.9 CL3
algorithm.
A= 1 0 2 1 B= 0 1 0 1
4 1 1 0 2 1 0 4
0 1 3 0 2 0 1 1
5 0 2 1 1 3 5 0