Professional Documents
Culture Documents
Ans) Asymptotic Notations are the expressions that are used to represent the complexity of an
algorithm.
Asymptotic notations are the mathematical notations used to describe the running time of an
For example: In bubble sort, when the input array is already sorted, the time taken by the
But, when the input array is in reverse condition, the algorithm takes the maximum time
When the input array is neither sorted nor in reverse order, then it takes average time. These
(a) Best Case: In which we analyse the performance of an algorithm for the input, for which the
(b) Worst Case: In which we analyse the performance of an algorithm for the input, for which the
(c) Average Case: In which we analyse the performance of an algorithm for the input, for which
the algorithm takes time or space that lies between best and worst case.
(a) Big-O Notation (Ο) – Big O notation specifically describes worst case scenario.
f(n)=O(g(n))
f(n)= O(n)
Eg: f(n)=3n+2
f(n)=Ω(g(n))
f(n)=Ω(n)
(c) Theta Notation (θ) – This notation represents the average complexity of an algorithm.
This notation describes both upper bound and lower bound running time complexity of an
algorithm.
Eg: f(n)=3n+2
f(n)=Ɵ(g(n))
3n+2=Ɵ(n)
f(n)=3n+2
f(n)=Ɵ(g(n))
3n+2=Ɵ(n)
f(n)=Ɵ(n)
f (n)
Little oh (o): The function f(n)=o g(n) [“read as f of n is little oh of g of n “ ] if and only lim =0
n→∞ g (n )
Little omega (ω): The function f(n)= ω g(n) [“read as f of n is little omega of g of n “ ] if and only
g (n )
lim =0
n→∞ f (n)
2) Explain Binary Search Algorithm and its time complexity with an example?
Ans) Binary search algorithm works on the principle of divide and conquer.
For this algorithm to work properly, the data collection should be in the sorted form.
Binary search looks for a particular item by comparing the middle most item of the collection. If a
if(a[mid]=X)
return mid;
If the middle item is greater than the item, then the item is searched in the sub-array to the left of
if(a[mid]>X)
Otherwise, the item is searched for in the sub-array to the right of the middle item.
if(a[mid]<X)
This process continues on the sub-array as well until the size of the subarray reduces to zero.
Algorithm:
Working Procedure:
3) Explain Merge Sort Algorithm and its time complexity with an example?
Ans) It works on the principle of Divide and Conquer.
Merge sort repeatedly breaks down a list into sub lists until each sub list consists of a single
element and merging those sub lists in a manner that results into a sorted list.
Algorithm:
Working Procedure:
4)Explain Quick Sort algorithm and its time complexity with an example?
Ans) Quick sort is a highly efficient sorting algorithm and is based on partitioning of array of data into
smaller arrays.
It is also called partition-exchange sort.
Pivot element can be any element from the array, it can be the first element, the last element or
any random element.
Algorithm:
Working Procedure:
Time Complexity:
5)Explain the general method of divide and conquer. Also explain the performance analysis?
Ans) In divide and conquer approach, a problem is divided into smaller problems, then the smaller
problems are solved independently, and finally the solutions of smaller problems are combined into
a solution for the large problem.
Generally, divide-and-conquer algorithms have three parts −
Divide: This involves dividing the problem into some sub problem.
Conquer: Sub problem by calling recursively until sub problem solved.
Combine: The Sub problem Solved so that we will get find problem solution.
Algorithm:
6) Explain the algorithm for finding maximum and minimum and its time complexity with an
example?
Ans) Algorithm for min and max is used to find the maximum and minimum elements in a set of n
elements.
Algorithm:
Time Complexity:
7) Explain Stressen’s Matrix Multiplication and its time complexity with an example?
Ans)
8) Explain time and space complexity with an example?
Ans)
DESIGN ANALYSIS AND ALGORITHM (DAA)
UNIT 2 QUESTION BANK ANSWERS
1)Explain the general method of greedy method. Define feasible solution and optimal solution?
Ans)
Algorithm:
2) Solve the job sequencing problem with number of jobs n = 4. Their profits are (p1,p2,p3,p4,p5) =
(100,10,15,27) and deadlines are (d1,d2,d3,d4) = ( 2,1,2,1). Write an algorithm for the same.
Ans)
Time complexity is Ɵ(n2 )
Best case is O(n)
3) Consider the weights and profits given and find the optimal solution where Max Capacity of
Knapsack, M =15, (p1,p2,p3,p4,p5,p6,p7) = (10,5,15,7,6,18,3) and (w1,w2,w3,w,4,w5,w6,w7) =
(2,3,5,7,1,4,1). Write an algorithm for the same.
Ans)
Time Complexity=O(n)
4) Explain optimal storage on tapes with an example?
Ans)
5) Explain Prim’s and Kruskal’s algorithm with an example?
Ans)