1
DEPARTMENT OF INFORMATION TECHNOLOGY
Subject Code : CS8451 Subject Name : Design & Analysis ofAlgorithms
Class/ Sem : II IT / II Sem Subject In – Charge : Dr. P. Subathra, Prof./IT
QUESTION BANK
UNIT III
DYNAMIC PROGRAMMING AND GREEDY TECHNIQUE Dynamic programming –
Principle of optimality - Coin changing problem, Computing a Binomial Coefficient – Floyd‘s
algorithm – Multi stage graph - Optimal Binary Search Trees – Knapsack Problem and Memory
functions. GREEDY TECHNIQUE – Container loading problem - Prim‘s algorithm and Kruskal's
Algorithm – 0/1 Knapsack problem, Optimal Merge pattern - Huffman Trees.
Q. No Question
Marks
Knowled
geLevel
Number
of
Times
inAU
PART - A
DYNAMIC PROGRAMMING
1. List out the memory functions used under Dynamic Programming. (R 13
APR/MAY 2015)
2. What do you mean by dynamic programming? (R 13 APR/MAY 2017)
What do you mean by dynamic programming? (R13 APR/MAY2019)
3. what are the differences between dynamic programming and divide and conquer
approaches? (R13 NOV/ DEC 2018)
DYNAMIC PROGRAMMING: PRINCIPLEOF OPTIMALITY
4. State the principle of optimality. (R 17 APR/MAY2019)
DYNAMIC PROGRAMMING: COIN CHANGING PROBLEM
5. Devise an algorithm to make for 1655 using the greedy strategy. The coins
available are {1000, 500, 100, 50, 20, 10, 5}. (R 13 APR/MAY 2017)
DYNAMIC PROGRAMMING: FLOYD‘S ALGORITHM
6. Write down the optimization technique used for Warshall’s algorithm. State the
rules and assumptions which are implied behind that. (R 13 APR/MAY 2015)
2
7. What does Floyd’s algorithm do? (R 13 NOV/ DEC 2017)
8. Define transitive closure of a directed graph. (R13 APR/MAY2018)
DYNAMIC PROGRAMMING: KNAPSACK PROBLEM ANDMEMORYFUNCTIONS
9. How dynamic programming is used to solve Knapsack problem? (R13 NOV/
DEC 2018)
GREEDY TECHNIQUE
10. State the generalprinciple of greedy algorithm. (R 13 APR/MAY 2017)
State the generalprinciple of greedy algorithm(R13 APR/MAY2019)
GREEDYTECHNIQUE : PRIM‘S ALGORITHM ANDKRUSKAL'S ALGORITHM
11.
12. Define the Single Source Shortest Path Problem. (R 13 MAY/JUN 2016)
13. How to calculate the efficiency of Dijkstra’s Algorithm? (R 13 NOV/ DEC 2016)
14. What is Euclidean minimum spanning tree problem? (R 13 MAY/JUN 2016)
15. Define the minimum spanning tree problem. (R13 APR/MAY2018)
Q. No Question
Marks
Knowled
geLevel
Number
of
Times
inAUPART - B
DYNAMIC PROGRAMMING
1. Explain the basic principle of dynamic programming using a simple example. (R
08 NOV/ DEC 2015) (10)
2. Explain the Dynamic Programming with an example. (R 08 NOV/ DEC 2010)
(16)
3. Compare and Contrast greedy algorithm and dynamic programming. (R 08
MAY/JUN 2013)
DYNAMIC PROGRAMMING: Floyd‘s algorithm
3
4. Solve the all pair shortest-path problem for the digraph with the following weight
matrix: (R 13 NOV/ DEC 2016) (16)
5. (Write the Floyd algorithm to find all pair shortest path and derive its time
complexity. (R 17 APR/MAY2019) (4+3)
Solve the following using Floyd's algorithm. (R 17 APR/MAY2019) (6)
6. Explain Floyds-Warshall algorithm using dynamic programming. Trace the
algorithm for the given example. (R13 NOV/ DEC 2018) (13)
DYNAMIC PROGRAMMING: Multi stage graph
7.
8.
DYNAMIC PROGRAMMING: Optimal Binary Search Trees
9. Write an algorithm to construct the optimal binary search tree given the roots
r(i,j), 0<=i<-j<=n. Also prove that this could be performed in time O(n). (R 13
APR/MAY 2015) (8)
DYNAMIC PROGRAMMING: Knapsack Problem and Memory functions
10. Find the optimal solution to the fractional knapsack problem with given data. (R
13 NOV/ DEC 2015) (8)
Item Weight Benefit
A 2 60
B 3 75
C 4 90
4
11. Solve the following instance of the 0/1 knapsack problem given the knapsack
capacity in W=5 using dynamic programming and explain it. (R 13 APR/MAY
2017) (13)
Item Weight Value
1 4 10
2 3 20
3 2 15
4 5 25
12. Find the optimal solution to the fractional knapsack problem wit given data: (R13
APR/MAY2019) (8)
13. Explain the memory function method for the knapsack problem and give the
algorithm. (R13 APR/MAY2018) (13)
14. DYNAMIC PROGRAMMING: TSP
15. Find the optimal tour in the following traveling salesperson problem using
dynamic programming : (R 08 NOV/ DEC 2009) (16)
GREEDY TECHNIQUE
16. Briefly discuss the applications of greedy algorithm. (R 08 NOV/ DEC 2009) (8)
17. Explain the Greedy method in detail with example. (R 08 NOV/ DEC 2015) (10)
GREEDYTECHNIQUE :Prim‘s Algorithm
18. Explain the working of Prim’s Algorithm. (R 13 NOV/ DEC 2017) (13)
19. Discuss about the algorithm and Pseudocode to find the Minimum Spanning Tree
using Prim’s Algorithm. Find the Minimum Spanning tree for the graph shown
below: And discuss the efficiency of the algorithm. (R 13 MAY/JUN 2016)
5
20. Consider the following weighted graph. Given the list of edges in the MST in the
order that Prim’s algorithm inserts them. Start Prim’s algorithm from vertex A. (R
13 NOV/ DEC 2015) (10)
21. Discuss about the algorithm and pseudocode to find the minimum spanning tree
using Prim's algorithm. Find the minimum spanning tree for the graph shown
below: And also discuss the efficiency of the algorithm. (R13 APR/MAY2019)
(13)
22. Give the pseudo code for Prim's algorithm and apply the same to find the
minimum spanning tree of the graph shown below:
GREEDYTECHNIQUE :Kruskal's Algorithm
23. Apply Kruskal’s algorithm to find a minimum spanning tree of the following
graph. (R 13 NOV/ DEC 2016)
24. How do you construct a minimum spanning tree using Kruskal’s algorithm?
Explain. (R 13 APR/MAY 2015) (4)
GREEDYTECHNIQUE :Dijkstra's Algorithm
25. Explain the Dijkstra’s shortest path algorithm and its efficiency. (R 13 NOV/ DEC
2017) (13)
26. Write and analyze the Prim’s Algorithm. (R 13 NOV/ DEC 2015) (6)
6
27. Explain how greedy approach is used in Dijkstra's algorithm for finding the
single-source shortest path for the given graph. (R13 NOV/ DEC 2018) (13)
GREEDYTECHNIQUE :0/1 Knapsack problem
28. Explain how knapsack’s problem is approached using greedy approach to arrive at
a solution. (R 08 APR/ MAY 2011) (10)
GREEDYTECHNIQUE : Huffman Trees.
29. Write the procedure to compute Huffman code. (R 13 NOV/ DEC 2015) (6)
30. Let A= {l/119. m/96, c/247, g/283, h/72, f/77, k/92, j/19} be the letter and its
frequency of distribution in a text file. Compute a suitable Huffman coding to
compress the data effectively. (R 13 APR/MAY 2015) (8)
31. Explain the concept of greedy algorithm with Huffman codes example. (R 08
NOV/ DEC 2010) (8)
32. Write the Huffman’s Algorithm. Construct the Huffman’s tree for the following
data and obtain its Huffman’s Code. (R 13 APR/MAY 2017) (13)
Characte
r
A B C D E -
Probabil
ity
0.
5
0.
35
0.
5
0.
1
0.
4
0.
2
33. The binary string below is the title of a song encoded using Huffman codes. (R 13
NOV/ DEC 2015)
Give the letter frequencies listed in the table below, build the Huffman codes and
use them to decode the title. In cases where there are multiple “greedy” choices,
the codes are assembled by combining the first letter (or group of letters) from left
to right, in the order given in the table. Also, the codes are assigned by labeling
the left and right branches of the prefix/ code tree with ‘0’ and ‘1’ respectively. (R
13 NOV/ DEC 2015) (10)
Let
ter
a h v w
‘
‘
e t l o
Fre
que
ncy
1 1 1 1 2 2 2 3 3
7
34. (b) (i) Write the Huffman code algorithm and derive its time complexity. (R 17
APR/MAY2019) (5+2)
(ii) Generate the Huffman code for the following data comprising of
alphabet and their frequency. a : 1, b : 1, c : 2, d : 3, e: 5,f : 8, g : 13, h :
21 (R 17 APR/MAY2019) (6)
Q. No Question
Marks
Knowled
geLevel
Number
of
Times
inAU
PART - C
DYNAMIC PROGRAMMING
1. The longest common subsequence (LCS) is the problem of finding the longest
subsequence the is present in the given two sequences in the same order but not
necessarily contiguously. write an algorithm using dynamic programming that
determines the LCS of two strings, 'x' and 'y' and returns the string 'z'.
(ii) Prove that any algorithm that searches need to necessarily do Ω(log n)
comparisons.
2. Given a matrix of order MxN, and two coordinates (p,q) and (r,s), which
represents te top-left and bottom-right of a sub-matrix of the matrix, MxN,
calculate the sum of elements present in the submatrix in O(1) time using dynamic
programming. Determine the optimal sub-structure and write an algorithm.
(10)
(ii) Prove that any algorithm that sorts by comparison, requires Ω (n log n)
time. (5)
DYNAMIC PROGRAMMING: Warshal‘s algorithm
8
3. Apply Warshall's algorithm to find the transitive closure of the digraph defined by
the following adjacency matrix.
Prove that the time efficiency of Warshall's algorithm is cubic. (R13 APR/MAY
2018) (7)
Explain why the time efficiency of Warshall's algorithm is inferior to that of the
traversal-based algorithm for sparse graphs represented by their adjacency lists.
(R13 APR/MAY2018) (8)
GREEDYTECHNIQUE :Prim‘s algorithm and Kruskal's Algorithm
4. Apply the greedy technique to fond the minimum spanning tree using Prim's
algorithm for the given graph. (R13 NOV/ DEC 2018) (15)
Staff In – Charge Subject Matter Expert HoD/IT

3. cs8451 daa anna univ question bank unit 3

  • 1.
    1 DEPARTMENT OF INFORMATIONTECHNOLOGY Subject Code : CS8451 Subject Name : Design & Analysis ofAlgorithms Class/ Sem : II IT / II Sem Subject In – Charge : Dr. P. Subathra, Prof./IT QUESTION BANK UNIT III DYNAMIC PROGRAMMING AND GREEDY TECHNIQUE Dynamic programming – Principle of optimality - Coin changing problem, Computing a Binomial Coefficient – Floyd‘s algorithm – Multi stage graph - Optimal Binary Search Trees – Knapsack Problem and Memory functions. GREEDY TECHNIQUE – Container loading problem - Prim‘s algorithm and Kruskal's Algorithm – 0/1 Knapsack problem, Optimal Merge pattern - Huffman Trees. Q. No Question Marks Knowled geLevel Number of Times inAU PART - A DYNAMIC PROGRAMMING 1. List out the memory functions used under Dynamic Programming. (R 13 APR/MAY 2015) 2. What do you mean by dynamic programming? (R 13 APR/MAY 2017) What do you mean by dynamic programming? (R13 APR/MAY2019) 3. what are the differences between dynamic programming and divide and conquer approaches? (R13 NOV/ DEC 2018) DYNAMIC PROGRAMMING: PRINCIPLEOF OPTIMALITY 4. State the principle of optimality. (R 17 APR/MAY2019) DYNAMIC PROGRAMMING: COIN CHANGING PROBLEM 5. Devise an algorithm to make for 1655 using the greedy strategy. The coins available are {1000, 500, 100, 50, 20, 10, 5}. (R 13 APR/MAY 2017) DYNAMIC PROGRAMMING: FLOYD‘S ALGORITHM 6. Write down the optimization technique used for Warshall’s algorithm. State the rules and assumptions which are implied behind that. (R 13 APR/MAY 2015)
  • 2.
    2 7. What doesFloyd’s algorithm do? (R 13 NOV/ DEC 2017) 8. Define transitive closure of a directed graph. (R13 APR/MAY2018) DYNAMIC PROGRAMMING: KNAPSACK PROBLEM ANDMEMORYFUNCTIONS 9. How dynamic programming is used to solve Knapsack problem? (R13 NOV/ DEC 2018) GREEDY TECHNIQUE 10. State the generalprinciple of greedy algorithm. (R 13 APR/MAY 2017) State the generalprinciple of greedy algorithm(R13 APR/MAY2019) GREEDYTECHNIQUE : PRIM‘S ALGORITHM ANDKRUSKAL'S ALGORITHM 11. 12. Define the Single Source Shortest Path Problem. (R 13 MAY/JUN 2016) 13. How to calculate the efficiency of Dijkstra’s Algorithm? (R 13 NOV/ DEC 2016) 14. What is Euclidean minimum spanning tree problem? (R 13 MAY/JUN 2016) 15. Define the minimum spanning tree problem. (R13 APR/MAY2018) Q. No Question Marks Knowled geLevel Number of Times inAUPART - B DYNAMIC PROGRAMMING 1. Explain the basic principle of dynamic programming using a simple example. (R 08 NOV/ DEC 2015) (10) 2. Explain the Dynamic Programming with an example. (R 08 NOV/ DEC 2010) (16) 3. Compare and Contrast greedy algorithm and dynamic programming. (R 08 MAY/JUN 2013) DYNAMIC PROGRAMMING: Floyd‘s algorithm
  • 3.
    3 4. Solve theall pair shortest-path problem for the digraph with the following weight matrix: (R 13 NOV/ DEC 2016) (16) 5. (Write the Floyd algorithm to find all pair shortest path and derive its time complexity. (R 17 APR/MAY2019) (4+3) Solve the following using Floyd's algorithm. (R 17 APR/MAY2019) (6) 6. Explain Floyds-Warshall algorithm using dynamic programming. Trace the algorithm for the given example. (R13 NOV/ DEC 2018) (13) DYNAMIC PROGRAMMING: Multi stage graph 7. 8. DYNAMIC PROGRAMMING: Optimal Binary Search Trees 9. Write an algorithm to construct the optimal binary search tree given the roots r(i,j), 0<=i<-j<=n. Also prove that this could be performed in time O(n). (R 13 APR/MAY 2015) (8) DYNAMIC PROGRAMMING: Knapsack Problem and Memory functions 10. Find the optimal solution to the fractional knapsack problem with given data. (R 13 NOV/ DEC 2015) (8) Item Weight Benefit A 2 60 B 3 75 C 4 90
  • 4.
    4 11. Solve thefollowing instance of the 0/1 knapsack problem given the knapsack capacity in W=5 using dynamic programming and explain it. (R 13 APR/MAY 2017) (13) Item Weight Value 1 4 10 2 3 20 3 2 15 4 5 25 12. Find the optimal solution to the fractional knapsack problem wit given data: (R13 APR/MAY2019) (8) 13. Explain the memory function method for the knapsack problem and give the algorithm. (R13 APR/MAY2018) (13) 14. DYNAMIC PROGRAMMING: TSP 15. Find the optimal tour in the following traveling salesperson problem using dynamic programming : (R 08 NOV/ DEC 2009) (16) GREEDY TECHNIQUE 16. Briefly discuss the applications of greedy algorithm. (R 08 NOV/ DEC 2009) (8) 17. Explain the Greedy method in detail with example. (R 08 NOV/ DEC 2015) (10) GREEDYTECHNIQUE :Prim‘s Algorithm 18. Explain the working of Prim’s Algorithm. (R 13 NOV/ DEC 2017) (13) 19. Discuss about the algorithm and Pseudocode to find the Minimum Spanning Tree using Prim’s Algorithm. Find the Minimum Spanning tree for the graph shown below: And discuss the efficiency of the algorithm. (R 13 MAY/JUN 2016)
  • 5.
    5 20. Consider thefollowing weighted graph. Given the list of edges in the MST in the order that Prim’s algorithm inserts them. Start Prim’s algorithm from vertex A. (R 13 NOV/ DEC 2015) (10) 21. Discuss about the algorithm and pseudocode to find the minimum spanning tree using Prim's algorithm. Find the minimum spanning tree for the graph shown below: And also discuss the efficiency of the algorithm. (R13 APR/MAY2019) (13) 22. Give the pseudo code for Prim's algorithm and apply the same to find the minimum spanning tree of the graph shown below: GREEDYTECHNIQUE :Kruskal's Algorithm 23. Apply Kruskal’s algorithm to find a minimum spanning tree of the following graph. (R 13 NOV/ DEC 2016) 24. How do you construct a minimum spanning tree using Kruskal’s algorithm? Explain. (R 13 APR/MAY 2015) (4) GREEDYTECHNIQUE :Dijkstra's Algorithm 25. Explain the Dijkstra’s shortest path algorithm and its efficiency. (R 13 NOV/ DEC 2017) (13) 26. Write and analyze the Prim’s Algorithm. (R 13 NOV/ DEC 2015) (6)
  • 6.
    6 27. Explain howgreedy approach is used in Dijkstra's algorithm for finding the single-source shortest path for the given graph. (R13 NOV/ DEC 2018) (13) GREEDYTECHNIQUE :0/1 Knapsack problem 28. Explain how knapsack’s problem is approached using greedy approach to arrive at a solution. (R 08 APR/ MAY 2011) (10) GREEDYTECHNIQUE : Huffman Trees. 29. Write the procedure to compute Huffman code. (R 13 NOV/ DEC 2015) (6) 30. Let A= {l/119. m/96, c/247, g/283, h/72, f/77, k/92, j/19} be the letter and its frequency of distribution in a text file. Compute a suitable Huffman coding to compress the data effectively. (R 13 APR/MAY 2015) (8) 31. Explain the concept of greedy algorithm with Huffman codes example. (R 08 NOV/ DEC 2010) (8) 32. Write the Huffman’s Algorithm. Construct the Huffman’s tree for the following data and obtain its Huffman’s Code. (R 13 APR/MAY 2017) (13) Characte r A B C D E - Probabil ity 0. 5 0. 35 0. 5 0. 1 0. 4 0. 2 33. The binary string below is the title of a song encoded using Huffman codes. (R 13 NOV/ DEC 2015) Give the letter frequencies listed in the table below, build the Huffman codes and use them to decode the title. In cases where there are multiple “greedy” choices, the codes are assembled by combining the first letter (or group of letters) from left to right, in the order given in the table. Also, the codes are assigned by labeling the left and right branches of the prefix/ code tree with ‘0’ and ‘1’ respectively. (R 13 NOV/ DEC 2015) (10) Let ter a h v w ‘ ‘ e t l o Fre que ncy 1 1 1 1 2 2 2 3 3
  • 7.
    7 34. (b) (i)Write the Huffman code algorithm and derive its time complexity. (R 17 APR/MAY2019) (5+2) (ii) Generate the Huffman code for the following data comprising of alphabet and their frequency. a : 1, b : 1, c : 2, d : 3, e: 5,f : 8, g : 13, h : 21 (R 17 APR/MAY2019) (6) Q. No Question Marks Knowled geLevel Number of Times inAU PART - C DYNAMIC PROGRAMMING 1. The longest common subsequence (LCS) is the problem of finding the longest subsequence the is present in the given two sequences in the same order but not necessarily contiguously. write an algorithm using dynamic programming that determines the LCS of two strings, 'x' and 'y' and returns the string 'z'. (ii) Prove that any algorithm that searches need to necessarily do Ω(log n) comparisons. 2. Given a matrix of order MxN, and two coordinates (p,q) and (r,s), which represents te top-left and bottom-right of a sub-matrix of the matrix, MxN, calculate the sum of elements present in the submatrix in O(1) time using dynamic programming. Determine the optimal sub-structure and write an algorithm. (10) (ii) Prove that any algorithm that sorts by comparison, requires Ω (n log n) time. (5) DYNAMIC PROGRAMMING: Warshal‘s algorithm
  • 8.
    8 3. Apply Warshall'salgorithm to find the transitive closure of the digraph defined by the following adjacency matrix. Prove that the time efficiency of Warshall's algorithm is cubic. (R13 APR/MAY 2018) (7) Explain why the time efficiency of Warshall's algorithm is inferior to that of the traversal-based algorithm for sparse graphs represented by their adjacency lists. (R13 APR/MAY2018) (8) GREEDYTECHNIQUE :Prim‘s algorithm and Kruskal's Algorithm 4. Apply the greedy technique to fond the minimum spanning tree using Prim's algorithm for the given graph. (R13 NOV/ DEC 2018) (15) Staff In – Charge Subject Matter Expert HoD/IT