Professional Documents
Culture Documents
QUESTION BANK
UNIT-I
SUB CODE: CS2251 DEPT: CSE
SUB NAME: DESIGN AND ANALYSIS OF ALGORITHMS SEM/YEAR: III/ II
PART A (2 Marks)
i 0
m
nm | ai | for n 1 f (n) O(n m ) where m is fixed .
i 0
12. An array has exactly n nodes. They are filled from the set {0, 1, 2,...,n-1, n}.
There are no duplicates in the list. Design an O(n) worst case time algorithm to
find which one of the elements from the above set is missing in the array. (AUC MAY
2011)
Algorithm:
Find (A[0,.n])
// Input: An array A[0n] filled with set values {0,1,2,.,n}
// Output: If all the array locations are filled returns 1 else returns -1.
i<- 0
While (i<=n) and (A[i]==i) do
i<- i+1
If i<=n return 1
else
return -1
13. Define Big Oh notation. (AUC MAY 2008/ MAY 2012)
A function t(n) is said to be in O(g(n)), denoted as t(n) O(g(n)), if t(n) is
bounded above by some constant multiple of g(n) for all large n.i.e., if there exist
some positive constant c and some non- negative integer n0 such that,
t(n) <= cg(n) for all n >=n0
14. What is meant by linear search? (AUC MAY 2012/DEC 2011)
Linear search algorithm is an algorithm which is used to find the location of the
key element x, by checking the successive elements of the array sequentially
one after another from the first location to the end of the array. The element may
or may not in the array. If the match is found then it is called successful search.
Otherwise it is called as unsuccessful search.
Worst case:
This analysis constrains on the input, other than size. Resulting in the fasters
possible run time
Average case:
This type of analysis results in average running time over every type of
input.
Complexity:
Complexity refers to the rate at which the storage time grows as a function
of the problem size
17. What is the explicit formula for the nth Fibonacci number?
The formula for the nth Fibonacci number is given by
T(n) = 1/
1. Explain how Time Complexity is calculated. Give an example (16) (AUC,MAY 2010)
The recurrence describes the running time of an algorithm that divides a problem of
size n into a sub problems, each of size n/b, where a and b are positive constants.
The a sub problems are solved recursively, each in time T (n/b). The cost of dividing
the problem and combining the results of the sub problems is described by the
function f (n). (That is, using the notation from, f(n) = D(n)+C(n).) For example, the
recurrence arising from the MERGE-SORT procedure has a = 2, b = 2, and f (n) =
(n).
As a matter of technical correctness, the recurrence isn't actually well defined
because n/b might not be an integer. Replacing each of the a terms T (n/b) with
either T (n/b) or T (n/b) doesn't affect the asymptotic behavior of the recurrence,
however. We normally find it convenient, therefore, to omit the floor and ceiling
functions when writing divide-and- conquer recurrences of this form.
4. What is linear search? Analyze linear search in terms of its time and space complexity.(16)
(AUC JUN 2010 /MAY 2011)
Explain how analysis of linear search is done with a suitable illustration. (10)(AUC DEC 2011)
Linear Search, as the name implies is a searching algorithm which obtains its result
by traversing a list of data items in a linear fashion. It will start at the beginning of a
list, and mosey on through until the desired element is found, or in some cases is
not found.
The aspect of Linear Search which makes it inefficient in this respect is that if the
element is not in the list it will have to go through the entire list. As you can imagine
this can be quite cumbersome for lists of very large magnitude, keep this in mind as
you contemplate how and where to implement this algorithm.
This puzzle asks you to move the disks from the left tower to the right tower, one disk at a
time so that a larger disk is never placed on a smaller disk. The goal is to use the smallest
Now that we know how to solve an n -disc problem, let's turn this into an algorithm
we can use.
If there is one disc, then we move 1 disc from the source pole to the destination
pole. Otherwise, we move n - 1 discs from the source pole to the temporary pole, we
move 1 disc from the source pole to the destination pole, and we finish by moving
the n - 1 discs from the temporary pole to the destination pole.
14. Write the recursive and non-recursive versions of the factorial function. Examine how
much time each function requires as n becomes large.(16) (AUC MAY 2011)
Write the recursive algorithm for computing Fibonacci numbers and solve its recurrence
relation. (16)