0% found this document useful (0 votes)
434 views5 pages

DAA Important Questions for Exams

The document contains 5 units that discuss important questions related to the design and analysis of algorithms. Some of the key questions asked include: 1. Analyzing the time complexity of recursive algorithms and determining the largest value of a such that one algorithm is asymptotically faster than another. 2. Solving recurrences and analyzing the time complexity of comparison-based sorting algorithms. 3. Using techniques like recursion trees to solve recurrences and explaining algorithms like quicksort, heapsort, and their time complexities. 4. Discussing concepts related to binary search trees, binomial heaps, Fibonacci heaps, and providing examples of operations on these data structures. 5. Analyzing greedy

Uploaded by

abhisheknath805
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
434 views5 pages

DAA Important Questions for Exams

The document contains 5 units that discuss important questions related to the design and analysis of algorithms. Some of the key questions asked include: 1. Analyzing the time complexity of recursive algorithms and determining the largest value of a such that one algorithm is asymptotically faster than another. 2. Solving recurrences and analyzing the time complexity of comparison-based sorting algorithms. 3. Using techniques like recursion trees to solve recurrences and explaining algorithms like quicksort, heapsort, and their time complexities. 4. Discussing concepts related to binary search trees, binomial heaps, Fibonacci heaps, and providing examples of operations on these data structures. 5. Analyzing greedy

Uploaded by

abhisheknath805
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Important Questions

Subject:- Design and Analysis of Algorithm

Unit-1

1. The recurrence T(n) = 7T(n/2) + n 2 describe the running time of an algorithm A. A


competing algorithm A has a running time T(n) = aT (n/4) + n 2. What is the largest
integer value for a A is asymptotically faster than A?
2.
i. Solve the recurrence T (n) = 2T(n/2) + n 2 + 2n + 1
ii. Prove that worst case running time of any comparison sort is  (n log n).
3. Use a recursion tree to give an asymptotically tight solution to the recurrence T(n) =
T(n) + T((1 – )n) + cn, where  is a constant in the range 0 <  0 is also a constant.
4. Explain the concepts of quick sort method and analyze its complexity with suitable
example.
5. Explain HEAP SORT on the array. Illustrate the operation HEAP SORT on the array A = {6,
14, 3, 25, 2, 10, 20, 7, 6}
6. What is the time complexity of counting sort? Illustrate the operation of counting sort
on array A = {1, 6, 3, 3, 4, 5, 6, 3, 4, 5}.
Unit-2

1. Insert the following element in an initially empty RB-Tree. 12, 9, 81, 76, 23, 43, 65, 88, 76,
32, 54. Now delete 23 and 81.
2. Using minimum degree ‘t’ as 3, insert following sequence of integers 10, 25, 20, 35, 30,
55, 40, 45, 50, 55, 60, 75, 70, 65, 80, 85 and 90 in an initially empty B-Tree. Give the
number of nodes splitting operations that take place.
3. What is a binomial heap? Describe the union of binomial heap.
OR
Explain the different conditions of getting union of two existing binomial heaps. Also
write algorithm for union of two binomial heaps. What is its complexity?
4. What is Fibonacci heap? Explain CONSOLIDATE operation with suitable example for
Fibonacci heap.
5. Write a Short note on:
a. Trie
b. Skip List
Unit-3

1. Discuss convex hull. Give Graham-Scan algorithm to compute convex hull.


OR
What do you mean by convex hull? Describe an algorithm that solves the convex hull
problem. Find the time complexity of the algorithm.
2. Explain “greedy algorithm” Write its pseudo code to prove that fractional Knapsack
problem has a greedy-choice property. Consider the weight and values of item listed
below. Note that there is only one unit of each item. The task is to pick a subset of these
items such that their total weight is no more than 11 kgs and their total value is
maximized. Moreover, no item may be split. The total value of items picked by an optimal
algorithm is denoted by Vopt. A greedy algorithm sorts the items by their value-to-weight
rations in descending order and packs them greedily, starting from the first item in the
ordered list. The total value of items picked by the greedy algorithm is denoted by Vgreedy.
Find the value of Vopt – Vgreedy.
Item I1 I2 I3 I4
W 10 7 4 2
V 60 28 20 24
3. Define minimum spanning tree (MST). Write Prim’s algorithm to generate an MST for any
given weighted graph. Generate MST for the following graph using the Prim’s
algorithm.

4. Explain Greedy programming in brief. Find the shortest path in the below graph from
the source vertex 1 to all other vertices by using Dijkstra’s algorithm.

5. Write down the Bellman Ford algorithm to solve the single source shortest path problem
also write its time complexity.
Unit-4

1. Discuss knapsack problem with respect to dynamic programming approach. Find the
optimal solution for given problem, w (weight set) = {5, 10, 15, 20} and W (Knapsack size)
= 25 and v = {50, 60, 120, 100}.

2. What do you understand by Dynamic Programming? Give Floyd-Warshall algorithm to


find the shortest path for all pairs of vertices in a graph. Give the complexity of the
algorithm. Apply the same on following graph.

3. What is the sum of subsets problem? Let w={5,7,10,12,15,18,20} and m=35. Find all
possible subsets of w that sum to m using recursive backtracking algorithm for it. Draw
the portion of the state-space tree that is generated.

4. Explain Branch and Bound method in brief. What is travelling salesman problem (TSP)?
Find the solution of following TSP using Branch & Bound method

5. What is backtracking? Explain the method of finding Hamiltonian cycles in a graph using
backtracking method with suitable example.
Unit-5

1. Explain and Write the Naïve-String string matching algorithm: Suppose the given pattern
p= aab and given text T = a c a a b c. Apply Naïve-String Matching algorithm on above
Pattern (P) and Text (T) to find the number of occurrences of P in T.

2. What is string matching algorithm? Explain Rabin-Karp method with examples.

3. Write KMP algorithm for string matching? Perform the KMP algorithm to search the
occurrences of the pattern abaab in the text string abbabaabaabab.

4. Explain approximation algorithm. Explore set cover problem using approximation


algorithm.

5. Write a short note on following:


i. Randomized Algorithm
ii. NP-Complete and NP Hard

Common questions

Powered by AI

Quicksort is a divide-and-conquer algorithm. It selects a pivot and partitions the array such that elements less than the pivot precede those greater. Recursively sorting the partitions leads to an overall sorted array. Its average and best-case complexity is O(n log n) while the worst case is O(n^2), often mitigated by randomizing the pivot selection. For example, sorting [6, 3, 8, 5, 2], choosing 5 as pivot, splits into [3, 2] and [6, 8], recursively sorting these and merging gives [2, 3, 5, 6, 8]. Quicksort is efficient on average, more so with tweaks like median-of-three pivot selection.

Heap Sort involves building a max heap from the input data, followed by repeatedly extracting the maximum element and restoring heap order. For A = {6, 14, 3, 25, 2, 10, 20, 7, 6}, start by building a max-heap, adjusting [6,14,3,25,2,10,20,7,6] to [25,14,20,7,2,10,3,6,6]. Extract 25 (the root), replacing it with the last element and reheapify, repeating this until the array is in order. The heap is reduced in size by 1 after each extraction, leading to sorted array [2,3,6,6,7,10,14,20,25]. Time complexity is O(n log n), where n is the number of elements.

The recursion tree method helps by visualizing the breakdown of the recursive calls. Each call branches into two new calls, with parameters αn and (1-α)n, respectively. The depth and width of the tree depend on α and 1-α, and leaf nodes handle base cases or small subproblems requiring O(n) time each. Summing the node contributions gives the dominant cost. For this recurrence structure, the work at each level of the tree creates a geometric series with a sum resolving to O(n log n) assuming c is positive and α is a fraction in (0,1). Hence, T(n) is O(n log n)

Recursive backtracking explores all possibilities for subsets, adding elements and checking if their sum matches the target. If it overshoots, backtrack to explore without the last element. For set {5, 7, 10, 12, 15, 18, 20}, recursively check subsets start at each element, maintaining the current sum and path. It finds subsets like {5,7,10,13}, {5,10,20}, that sum 35 by adding elements to the solution path recursively and backtracking when path invalidates. This method’s complexity is exponential in the number of items due to checking all subsets.

Prim's algorithm grows the MST from an initial vertex, repeatedly adding the smallest edge that extends the MST to a new vertex. It uses a priority queue to track the minimum edge crossing the cut between MST and unvisited vertices. Starting from any node, it picks the least weight edge to a non-MST node and repeats until all nodes are included. For example, given a graph, starting at vertex A with edges AB(1), AC(3), Prim’s selects AB then examines B’s edges, continually adding minimum edges until all nodes are spanned efficiently. It guarantees MST with complexity O(V^2) for adjacency matrices or O(E log V) using priority queues with adjacency lists.

Dynamic programming is a method for solving complex problems by breaking them down into simpler subproblems, storing their solutions to avoid redundant work. In the 0/1 Knapsack problem, we create a table where rows represent items and columns represent weight capacity up to the knapsack size. By filling the table based on maximum achievable value without exceeding capacity, we deduce the optimal composition. For weights {5,10,15,20} and values {50,60,120,100} with knapsack size 25, evaluate inclusion/exclusion of each item. Resulting in maximum value 170 achieved by selecting items of weights 5 and 20, values 50 and 120. Complexity is O(nW), n being number of items, W the knapsack capacity.

The Naïve-String Matching algorithm checks for pattern appearance by systematically aligning the pattern with each substring of the text with the same length, allowing shifts by one character when mismatches arise. For pattern 'aab' and text 'acaabc', align from index 0: check 'aca', no match, shift; check 'caa', no match, shift; check 'aab', match as 'aac' - mismatch; check 'abc' - no match found starting from index positions. Only one occurrence at index 2 of 'acaabc'. Thus, only one complete match is found. Its complexity is O((n-m+1)m) for text length n and pattern length m.

A binomial heap is a collection of binomial trees that satisfies the heap property. Trees are linked to each other such that each tree’s root is either the smallest (min-heap) or largest (max-heap) element. The union operation merges two binomial heaps by linking trees of the same degree, similar to the merging process of linked lists, while maintaining the heap property through a series of 'carries'. Its complexity is O(log n) due to the hierarchical structure of the trees.

Approximation algorithms are used to find near-optimal solutions to NP-hard problems within bounds on the deviation from the best solution. For the set cover problem (finding a minimum set of subsets whose union covers a set), a common heuristic selects subsets with the most uncovered elements iteratively. This greedy approach yields a solution within a logarithmic factor of the optimal size (ln n factor for n elements). For example, given universal set U and a collection of subsets, iteratively select the subset covering the maximum number of uncovered elements until U is covered. Despite not guaranteeing optimality, it solves instances efficiently and is practically useful with predictable performance bounds.

To determine this, we compare the two recurrences. For T(n) = 7T(n/2) + n^2, using the Master Theorem, the critical exponent is 2, giving us a complexity of Θ(n^log₂7). For T'(n) = aT'(n/4) + n^2, using the Master Theorem, the critical exponent here is 2 also, which simplifies to Θ(n^log₄a). For T'(n) to be asymptotically faster than T(n), we need Θ(n^log₄a) < Θ(n^log₂7). Therefore, log₄a < log₂7, which implies a < 7^log₄2. Computing 7^log₄2, we find a < 3.5. Hence, the largest integer value for 'a' is 3.

You might also like