39
Dr. N.G.P. Institute of Technology, Coimbatore – 48. Department of Information Technology DESIGN AND ANALYSIS OF ALGORITHMS Class: III B.Tech IT Semester: 05 Regulation: 2008 QUESTION BANK UNIT I - INTRODUCTION PART A: 1. Define Algorithms. 2. What are the various criteria of an algorithm? 3. What is algorithm validation? 4. Define program verification. 5. Define performance analysis (or) analysis of an algorithm. 6. What is debugging? 7. What is performance measurement? 8. Mention the criteria for judging an algorithm. 9. Define space/time complexity. 10. Define best case, average case and worst-case analysis. 11. What are the various asymptotic notations? 12. Define Oh notation. 13. Define omega notation. 14. Define theta notation. 15. What are the properties of algorithm? 16. Explain Divide and Conquer approach. 17. Specify a method for detecting a counterfeit coin in a bag. 18. Write the general algorithm for Divide and Conquer approach. 19. Write the recurrence relation for Divide and Conquer approach. 20. Solve the following recurrence relation. 1. a=1 , b=2 and f(n)=cn 2. a=5 , b=4 and f(n)=cn 2 3. a=28 , b=3 and f(n)=cn 3 21. Define Binary search 22. Explain the Divide and conquer solution for a binary search problem. 23. Draw binary decision tree for binary search N=14. 24. Define Internal and External nodes 25. Define internal path length and External path length 26. Write the computing time for binary search for successful and unsuccessful search. 27. State the problem of finding the maximum and minimum element.

DAA Question Bank

Embed Size (px)

Citation preview

Page 1: DAA Question Bank

Dr. N.G.P. Institute of Technology, Coimbatore – 48.

Department of Information Technology

DESIGN AND ANALYSIS OF ALGORITHMS

Class: III B.Tech IT Semester: 05 Regulation: 2008

QUESTION BANK

UNIT I - INTRODUCTION

PART A: 1. Define Algorithms. 2. What are the various criteria of an algorithm? 3. What is algorithm validation? 4. Define program verification. 5. Define performance analysis (or) analysis of an algorithm. 6. What is debugging? 7. What is performance measurement? 8. Mention the criteria for judging an algorithm. 9. Define space/time complexity. 10. Define best case, average case and worst-case analysis. 11. What are the various asymptotic notations? 12. Define Oh notation. 13. Define omega notation. 14. Define theta notation. 15. What are the properties of algorithm? 16. Explain Divide and Conquer approach. 17. Specify a method for detecting a counterfeit coin in a bag. 18. Write the general algorithm for Divide and Conquer approach. 19. Write the recurrence relation for Divide and Conquer approach. 20. Solve the following recurrence relation. 1. a=1 , b=2 and f(n)=cn

2. a=5 , b=4 and f(n)=cn2 3. a=28 , b=3 and f(n)=cn3

21. Define Binary search 22. Explain the Divide and conquer solution for a binary search problem. 23. Draw binary decision tree for binary search N=14. 24. Define Internal and External nodes 25. Define internal path length and External path length 26. Write the computing time for binary search for successful and unsuccessful search. 27. State the problem of finding the maximum and minimum element.

Page 2: DAA Question Bank

28. State the divide and conquer approach for finding maximum and minimum element & write the recurrence relation. 29. Define merge sort. 30. Define insertion sort. 31. Define Quick sort. 32. Define Selection sort. 33. Define Heap sort. 34. Write the heap sort routine. 35. Compare the efficiency of all the sorting algorithms. PART-B

1. Explain the analysis of divide and conquer algorithm. 2. Define binary search. Write the iterative and recursive version for solving binary

search problem with an illustration. 3. Solve the problem of finding maximum and minimum element and derive the

efficiency relation. 4. Explain merge sort and derive the efficiency relation. 5. Write the merge sort algorithm and illustrate with an example. 6. Explain quick sort with an illustration. 7. Explain

1. Selection sort 2. Heap sort.

UNIT II GREEDY METHOD

PART A

1. Define greedy method. 2. Define feasible and optimal solutions. 3. What are the categories of problem in greedy method? 4. Define Subset Paradigm with e.g. 5. Write the control abstraction for subset paradigm? 6. Define ordering paradigm with e.g. 7. What is change making problem? Give the greedy solution to solve the problem. 8. What is machine-scheduling problem? Give a feasible solution. 9. State the optimal storage on tape problem. 10. Give a solution for optimal storage on tape problem and write the efficiency

equation. 11. State Knapsack problem. 12. Mention the four greedy solutions for knapsack problem. 13. Write the general rule to solve knapsack problem. 14. Define spanning tree and mention its application. 15. State minimum spanning tree problem. 16. Mention the optimization criteria for minimum spanning tree problem. 17. What are the two ways for solving minimum spanning tree problem and state the

efficiency equation.

Page 3: DAA Question Bank

18. Define Bourvka step. 19. State single source shortest path problem and give a solution. 20. Define Dijkstra’s algorithm and write the overall run time. 21. Compare Divide and conquer and greedy technique.

PART B:

1. Explain the general greedy method. 2. State minimum spanning tree problem and mention the ways to solve it. 3. Explain optimal storage on tape problem and write an algorithm to solve it. 4. Explain Knapsack problem with an algorithm. Give an illustration for knapsack

problem. 5. Explain Prim’s algorithm and Kruskal’s algorithm with an e.g. 6. State single source shortest path problem. Explain Dijkstra’s algorithm to solve

the problem.

UNIT III DYNAMIC PROGRAMMING

PART A:

1. Define dynamic programming. 2. Differentiate divide & conquer with DP. 3. Differentiate greedy technique & DP. 4. Define principle of optimality. 5. Justify principle of optimality with an example. 6. State multistage graph problem. 7. Propose a solution for multistage graph problem. 8. Specify the equation for forward & backward approach to solve multistage graph problem. 9. State all pair shortest path problem. 10. State Floyd’s algorithm for solving all pair shortest path problem. 11. Define OBST. 12. What is the application of OBST? 13. Mention the method to solve the OBST. PART-B:

1. Explain the dynamic programming method of solving a problem. 2. Explain all pair shortest path problems & an algorithm to solve it. 3. Discuss optimal binary search tree & algorithm to solve OBST. 4. Explain forward & backward approach to solve multistage graph problem.

Page 4: DAA Question Bank

UNIT IV BACKTRACKING

PART A:

1. Distinguish between backtracking and dynamic programming. 2. Explain backtracking technique. 3. Define explicit and implicit constraints. 4. Define solution space. 5. Mention the purpose of tree organization. 6. What is problem state? 7. What is state space and state space tree? 8. Define solution state and answer state. 9. Define static and dynamic tree. 10. What are live node and dead node? 11. What is E-node? 12. State 8 queen’s problem. 13. What is the bounding function for sum of subset problem? 14. Write the bounding function for sum of subset problem. 15. State m-colorability decision problem 16. State m-colorability optimization problem. 17. Define planar graph.

PART B:

1. Explain backtracking technique. Write the iterative and recursive backtracking algorithm.

2. State 8 queen’s problem. Propose an algorithm using backtracking technique to solve the same.

3. Explain in detail about sum of subset problem. Illustrate with an example. 4. Discuss in detail about the graph-coloring problem. 5. Propose a solution for knapsack problem using backtracking technique and

explain with an algorithm.

UNIT V BRANCH AND BOUND

PART A:

1. Define branch and bound strategy. 2. Compare BFS and DFS like state space tree in branch and bound. 3. What is optimization problem? 4. Explain optimal and feasible solution. 5. What are the two principal ideas of branch and bound algorithm? 6. State the three conditions to terminate a state space tree of branch and bound

algorithm. 7. What is FIFO branch and bound algorithm? 8. What is least cost search? 9. What is the ideal way to assign ranks? 10. State the branch and bound strategy to solve knapsack problem. 11. Write the way to compute upper bound in knapsack problem.

Page 5: DAA Question Bank

12. State traveling salesman problem. 13. Mention the ways to compute the lower bound for traveling salesman problem. 14. Explain dominance relation. 15. When can we say a dominance relation D2 is stronger than D1? 16. What are the two groups of algorithm depending on computing times? 17. Mention the properties of NP-complete problem. 18. Define deterministic algorithm. 19. Define non-deterministic algorithm. 20. Specify the three functions in non-deterministic algorithm. 21. What is non-deterministic machine? 22. Write a non-deterministic algorithm for searching problem. 23. What is decision problem and decision algorithm? 24. What is optimization problem and optimization algorithm? 25. What is maximum clique? State maximum clique problem. 26. State satisfiability problem. 27. State polynomial complexity of an algorithm. 28. Draw the relationship diagram of P, NP, and NP-complete and NP- hard problem. 29. Define NP-hard and NP-complete problem. 30. State halting problem. 31. Define reducibility.

PART- B

1. Explain least cost branch and bound in detail. 2. State TSP and a method to solve it. Give an illustration. 3. Explain branch and bound algorithm to solve knapsack problem. 4. Discuss about NP-Hard and NP-Complete problem. 5.

TWO MARK QUESTIONS WITH ANSWERS:

UNIT I INTRODUCTION

1. Why is the need of studying algorithms?

From a practical standpoint, a standard set of algorithms from different areas of computing must be known, in addition to be able to design them and analyze their efficiencies. In this theoretical standpoint the study of algorithms in the cornerstone of computer science.

2. What is algorithmics?

The study of algorithms is called algorithmics. It is more than a branch of computer science. It is the core of computer science and is said to be relevant to most of science, business and technology.

Page 6: DAA Question Bank

3. What is an algorithm?

An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate input in finite amount of time.

4. Give the diagram representation of Notion of algorithm.

5. What are the fundamental steps involved in algorithmic problem solving?

The fundamental steps are Understanding the problem Ascertain the capabilities of computational device Choose between exact and approximate problem solving Decide on appropriate data structures Algorithm design techniques Methods for specifying the algorithm Proving an algorithms correctness Analyzing an algorithm Coding an algorithm

6. What are the characteristics of an algorithm?

Every algorithm should have the following five characteristics (i) Input (ii) Output (iii) Definiteness (iv) Effectiveness (v) Termination

Therefore, an algorithm can be defined as a sequence of definite and effective instructions, which terminates with the production of correct output from the given input. In other words, viewed little more formally, an algorithm is a step by step formalization of a mapping function to map input set onto an output set.

Page 7: DAA Question Bank

7. What is an algorithm design technique?

An algorithm design technique is a general approach to solving problems algorithmically that is applicable to a variety of problems from different areas of computing. General design techniques are: (i) Brute force (ii) divide and conquer (iii) decrease and conquer (iv) transform and concquer (v) greedy technique (vi) dynamic programming (vii) backtracking (viii) branch and bound

8. What is pseudocode?

A pseudocode is a mixture of a natural language and programming language constructs to specify an algorithm. A pseudocode is more precise than a natural language and its usage often yields more concise algorithm descriptions.

9. What are the types of algorithm efficiencies?

The two types of algorithm efficiencies are Time efficiency: indicates how fast the algorithm runs Space efficiency: indicates how much extra memory the algorithm

needs

10. What is the basic operation of an algorithm and how is it identified?

The most important operation of the algorithm is called the basic operation of the algorithm, the operation that contributes the most to the total running time. It can be identified easily because it is usually the most time consuming operation in the algorithms innermost loop.

11. What is the running time of a program implementing the algorithm?

The running time T(n) is given by the following formula

cop is the time of execution of an algorithm’s basic operation on a particular computer and C(n) is the number of times this operation needs to be executed for the particular algorithm.

12. What are exponential growth functions?

The functions 2n and n! are exponential growth functions, because these two functions grow so fast that their values become astronomically large even for rather smaller values of n.

13. What is worst-case efficiency?

The worst-case efficiency of an algorithm is its efficiency for the worst-case input of size n, which is an input or inputs of size n for which the algorithm runs the longest among all possible inputs of that size.

Page 8: DAA Question Bank

14. What is best-case efficiency?

The best-case efficiency of an algorithm is its efficiency for the best-case input of size n, which is an input or inputs for which the algorithm runs the fastest among all possible inputs of that size.

15. What is average case efficiency?

The average case efficiency of an algorithm is its efficiency for an average case input of size n. It provides information about an algorithm behavior on a “typical” or “random” input.

16. What is amortized efficiency?

In some situations a single operation can be expensive, but the total time for the entire sequence of n such operations is always significantly better that the worst case efficiency of that single operation multiplied by n. this is called amortized efficiency.

17. What are the basic asymptotic efficiency classes?

The various basic efficiency classes are Constant : 1 Logarithmic : log n Linear : n N-log-n : nlog n Quadratic : n2 Cubic : n3 Exponential : 2n Factorial : n!

18. Write the general plan for analyzing the efficiency for non-recursive algorithms.

The various steps include Decide on a parameter indicating input’s size. Identify the algorithms basic operation. Check whether the number of times the basic operation is executed

depends on size of input. If it depends on some additional property the worst, average and best-case efficiencies have to be investigated separately.

Set up a sum expressing the number of times the algorithm’s basic operation is executed.

Using standard formulas and rules of manipulation, find a closed-form formula for the count or at least establish its order of growth.

19. Write the general plan for analyzing the efficiency for recursive algorithms.

The various steps include Decide on a parameter indicating input’s size.

Page 9: DAA Question Bank

Identify the algorithms basic operation. Check whether the number of times the basic operation is executed

depends on size of input. If it depends on some additional property the worst, average and best-case efficiencies have to be investigated separately.

Set up a recurrence relation with the appropriate initial condition , for the number of times the basic operation is executed.

Solve the recurrence or at least ascertain the orders of growth of its solution.

20. Give the various system commands used for timing the program implementing the

algorithm.

The system commands are as follows UNIX time command C & C++ function clock

Java method currentTimeMillis() in the System class

21. What is algorithm visualization?

Algorithm visualization is a way to study algorithms. It is defined as the use of images to convey some useful information about algorithms. That information can be a visual illustration of algorithm’s operation, of its performance on different kinds of inputs, or of its execution speed versus that of other algorithms for the same problem.

22. What is Big ‘Oh’ notation?

A function t(n) is said to be in O(g(n)), denoted 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 nonnegative integers n

0 such that

t(n)<= cg(n) for all n≥ n

0

23. Define Big Theta Notations

A function t(n) is said to be in Θ(g(n)) , denoted t(n) Є Θ (g(n)) , if t(n) is bounded both above and below by some positive constant multiple of g(n) for all large n, i.e., if there exist some positive constants c1 and c2 and some nonnegative integer n0 such that c1 g(n) ≤t(n) ≤ c2g(n) for all n ≥ n0

24. Define Big Omega Notations

A function t(n) is said to be in Ω(g(n)) , denoted t(n) Є Ω((g(n)) , if t(n) is bounded below by some positive constant multiple of g(n) for all large n, i.e., if there exist some positive constant c and some nonnegative integer n0 such that t(n) ≥cg(n) for all for all n ≥ n0

Page 10: DAA Question Bank

25. Define order of an algorithm

Measuring the performance of an algorithm in relation with the input size n is known as order of growth.

26. What is recursive call?

Recursive algorithm makes more than a single call to itself is known as recursive call. An algorithm that calls itself is direct recursive.An algorithm”A” is said to be indirect recursive if it calls another algorithm which in turn calls “A”.

27. Analyze the time complexity of the following segment:

for(i=0;i<N;i++) for(j=N/2;j>0;j--) sum++;

Time Complexity= N * N/2 = N

2 /2

Є O(N2)

28. Define Brute force approach?

Brute force is a straightforward approach to solving a problem, usually directly based on the problem’s statement and definitions of the concepts involved. The brute force approach is one that is easiest to apply.

29. What are the advantages of brute force technique?

The various advantages of brute force technique are Brute force applicable to a very wide variety of problems. It is

used for many elementary but important algorithmic tasks For some important problems this approach yields reasonable

algorithms of at least some practical value with no limitation on instance size

The expense to design a more efficient algorithm may be unjustifiable if only a few instances of problems need to be solved and a brute force algorithm can solve those instances with acceptable speed

Even if inefficient in general it can still be used for solving small-size instances of a problem

It can serve as a yardstick with which to judge more efficient alternatives for solving a problem

30. What is selection sort?

Selection sort is started by scanning the entire list to find the smallest element and exchange it with the first element, putting the first element in the final position in

Page 11: DAA Question Bank

the sorted list. Then the scan starts from the second element to find the smallest among n-1 elements and exchange it with the second element.

In their final position the last n-i elements

31. Mention the pseudo code for selection sort.

32. What is bubble sort?

Another brute force approach to sort a problem is to compare adjacent elements of the list and exchange them if they are out of order, so we end up “bubbling up” the largest element to the last position in the list. The next pass bubbles up the second largest element, and so on until n-1 passes, the list is sorted. Pass I can be represented as follows

In their final positions

33. Give the benefit of application of brute force technique to solve a problem.

With the application of brute force strategy, the first version of an algorithm obtained can often be improved with a modest amount of effort. So a first application of the brute force approach often results in an algorithm that can be improved with a modest amount of effort.

34. Give the general plan for divide-and-conquer algorithms.

The general plan is as follows A problems instance is divided into several smaller instances of the same

problem, ideally about the same size The smaller instances are solved, typically recursively If necessary the solutions obtained are combined to get the solution of the

original problem

Page 12: DAA Question Bank

35. State the Master theorem and its use.

36. What is the general divide-and-conquer recurrence relation?

An instance of size ‘n’ can be divided into several instances of size n/b, with ‘a’ of them needing to be solved. Assuming that size ‘n’ is a power of ‘b’, to simplify the analysis, the following recurrence for the running time is obtained: T(n) = aT(n/b)+f(n) Where f(n) is a function that accounts for the time spent on dividing the problem into smaller ones and on combining their solutions.

37. Define control abstraction.

A control abstraction we mean a procedure whose flow of control is clear but whose primary operations are by other procedures whose precise meanings are left undefined. Write the Control abstraction for Divide-and conquer.

Algorithm DAndC(P) { if small(p) then return S(P); else { divide P into smaller instance p1,p2,…p

k, k ≥1;

Apply DAndC to each of these subproblems Return combine (DAnd C(p1) DAnd C(p2),----, DAnd (pk)); } }

38. Define mergesort.

Mergesort sorts a given array A[0..n-1] by dividing it into two halves a[0..(n/2). .1] and A[n/2..n-1] sorting each of them recursively and then merging the two smaller sorted arrays into a single sorted one.

39. What is the difference between quicksort and mergesort?

Both quicksort and mergesort use the divide-and-conquer technique in which the given array is partitioned into subarrays and solved. The difference lies in the

Page 13: DAA Question Bank

technique that the arrays are partitioned. For mergesort the arrays are partitioned according to their position and in quicksort they are partitioned according to the element values.

40. What is binary search?

Binary search is a remarkably efficient algorithm for searching in a sorted array. It works by comparing a search key K with the arrays middle element A[m]. if they match the algorithm stops; otherwise the same operation is repeated recursively for the first half of the array if K < A[m] and the second half if K > A[m]. A[0]………A[m-1] A[m] A[m+1]………A[n-1] search here if K<A[m] search here if K>A[m]

41. What is the maximum and minimum problem?

The problem is to find the maximum and minimum items in a set of ‘n’ elements. Though this problem may look so simple as to be contrived, it allows us to demonstrate divideand-conquer in simple setting.

42. Write an algorithm for straightforward maximum and minimum?

Algorithm straight MaxMin(a,n,max,min) //set max to the maximum and min to the minimum of a[1:n] { max := min: = a[i]; for i = 2 to n do { if(a[i] >max) then max: = a[i]; if(a[i] >min) then min: = a[i]; } }

43. What is insertion sort?

Insertion sort in an application of decrease-by-one technique to sort an array A[0..n-1]. We assume that the smaller problem of sorting an array A[0..n-2] has already been solved to give us a sorted array of size n-1. Then an appropriate position for A[n-1] is found among the sorted element and then the element is inserted.

44. What is a tree edge and back edge?

In the depth first search forest, whenever a new unvisited vertex is reached for the first time, it is attached as a child to the vertex from which it is being reached. Such an edge is called tree edge because the set of all such edges forms a forest. The algorithm encounters an edge leading to a previously visited vertex other than its immediate predecessor. Such an edge is called a back edge because it connects a vertex to its ancestor, other than the parent, in the depth first search forest.

Page 14: DAA Question Bank

45. What is a tree edge and cross edge?

In the breadth first search forest, whenever a new unvisited vertex is reached for the first time, it is attached as a child to the vertex from which it is being reached. Such an edge is called tree edge. If an edge is leading to a previously visited vertex other than its immediate predecessor that edge is noted as cross edge.

46. What is a heap?

A heap is a partially ordered data structure, and can be defined as a binary tree assigned to its nodes, one key per node, provided the following two conditions are met

The tree’s shape requirement-The binary tree is essentially complete, that is all the leaves are full except possibly the last level, where only some rightmost leaves will be missing.

The parental dominance requirement-The key at each node is greater that or equal to the keys of its children

47. What is the main use of heap?

Heaps are especially suitable for implementing priority queues. Priority queue is a set of items with orderable characteristic called an item’s priority, with the following operations

Finding an item with the highest priority Deleting an item with highest priority Adding a new item to the set

48. Give three properties of heaps?

The properties of heap are There exists exactly one essentially complete binary tree with ‘n’ nodes.

Its height is equal to log2n The root of the heap is always the largest element A node of a heap considered with all its descendants is also a heap

49. Give the main property of a heap that is implemented as an array.

A heap can be implemented as an array by recording its elements in the top-down, left-to-right fashion. It is convenient to store the heap’s elements in positions 1 through n of such an array. In such a representation

Page 15: DAA Question Bank

50. What are the two alternatives that are used to construct a heap?

The two alternatives to construct a heap are Bottom-up heap construction Top-down heap construction

51. What is the algorithm to delete the root’s key from the heap?

ALGORITHM Exchange the root’s key with the last key K of the heap Decrease the heap’s size by one “Heapify” the smaller tree by sifting K down the tree exactly in the same

way as bottom-up heap construction. Verify the parental dominance for K: if it holds stop the process, if not swap K with the larger of its children and repeat this operation until the parental dominance holds for K in its new position.

52. Who discovered heap sort and how does it work?

Heap sort was discovered by J.W.J. Williams. This is a two stage process that works as follows

Stage 1 Heap construction: construct a heap for a given array. Stage 2 Maximum deletions: Apply the root deletion operation n-1 times

to the remaining heap

UNIT II GREEDY METHOD

1. What is dynamic programming and who discovered it?

Dynamic programming is a technique for solving problems with overlapping subproblems. These subproblems arise from a recurrence relating a solution to a given problem with solutions to its smaller subproblems only once and recording the results in a table from which the solution to the original problem is obtained. It was invented by a prominent U.S Mathematician, Richard Bellman in the 1950s.

2. What is greedy technique?

Greedy technique suggests a greedy grab of the best alternative available in the hope that a sequence of locally optimal choices will yield a globally optimal solution to the entire problem. The choice must be made as follow

Feasible : It has to satisfy the problem’s constraints Locally optimal : It has to be the best local choice among all feasible

choices available on that step Irrevocable : Once made, it cannot be changed on a subsequent step of the

algorithm

Page 16: DAA Question Bank

3. What are the labels in Prim’s algorithm used for?

Prim’s algorithm makes it necessary to provide each vertex not in the current tree with the information about the shortest edge connecting the vertex to a tree vertex. The information is provided by attaching two labels to a vertex

The name of the nearest tree vertex The length of the corresponding edge

4. How are the vertices not in the tree split into?

The vertices that are not in the tree are split into two sets Fringe: It contains the vertices that are not in the tree but are adjacent to

atleast one tree vertex. Unseen: All other vertices of the graph are called unseen because they are

yet to be affected by the algorithm.

5. What are the operations to be done after identifying a vertex u* to be added to the

tree?

After identifying a vertex u* to be added to the tree, the following two operations need to be performed

Move u* from the set V-VT to the set of tree vertices VT* For each remaining vertex u in V-VT that is connected to u by a shorter

edge than the u’s current distance label, update its labels by u* and the weight of the edge between u* and u, respectively.

6. What is a min-heap?

A min-heap is a mirror image of the heap structure. It is a complete binary tree in which every element is less than or equal to its children. So the root of the min-heap contains the smallest element.

7. What is the use of Kruskal’s algorithm and who discovered it?

Kruskal’s algorithm is one of the greedy techniques to solve the minimum spanning tree problem. It was discovered by Joseph Kruskal when he was a second-year graduate student.

8. What is a subset’s representative?

One element from each of the disjoint subsets in a collection is used as the subset’s representative. Some implementations do not impose any specific constraints on such a representative; others do so by requiring the smallest element of each subset to be used as the subset’s representative.

9. What is the use of Dijksra’s algorithm?

Dijkstra’s algorithm is used to solve the single-source shortest-paths problem: for a given vertex called the source in a weighted connected graph, find the shortest

Page 17: DAA Question Bank

path to all its other vertices. The single-source shortest-paths problem asks for a family of paths, each leading from the source to a different vertex in the graph, though some paths may have edges in common.

10. Write the control abstraction for greedy method.

Algorithm Greedy (a, n) { solution=0; for i=1 to n do { x= select(a); if feasible(solution ,x) then solution=Union(solution ,x); } return solution; }

11. Define feasible and optimal solution.

Given n inputs and we are required to form a subset such that it satisfies some given constraints then such a subset is called feasible solution. A feasible solution either maximizes or minimizes the given objective function is called as optimal solution

12. What are the constraints of knapsack problem?

To maximize Σpix

i

1≤i≤n The constraint is: Σw

ix

i ≥ m and 0 ≤ x

i ≤ 1, 1≤ i ≤ n

1≤i≤n where m is the bag capacity, n is the number of objects and for each object i w

i and p

i are the weight and profit of object respectively.

13. What is a minimum cost spanning tree?

A spanning tree of a connected graph is its connected acyclic subgraph that contains all vertices of a graph. A minimum spanning tree of a weighted connected graph is its spanning tree of the smallest weight where bweight of the tree is the sum of weights on all its edges. A minimum spanning subtree of a weighted graph (G,w) is a spanning subtree of G of minimum weight w(T )= Σ w(e ), e € T. Minimum Spanning Subtree Problem: Given a weighted connected undirected graph (G,w), find a minimum spanning subtree

14. Specify the algorithms used for constructing Minimum cost spanning tree.

Page 18: DAA Question Bank

a) Prim’s Algorithm b) Kruskal’s Algorithm

15. State single source shortest path algorithm (Dijkstra’s algorithm).

For a given vertex called the source in a weigted connected graph,find shotrtest paths to all its other vertices.Dijikstra’s algorithm applies to graph with non-negative weights only.

16. What is Knapsack problem?

A bag or sack is given capacity and n objects are given. Each object has weight wi and profit pi .Fraction of object is considered as xi (i.e) 0<=xi<=1 .If fraction is 1 then entire object is put into sack. When we place this fraction into the sack we get wixi and pixi.

17. Write any two characteristics of Greedy Algorithm?

* To solve a problem in an optimal way construct the solution from given set of candidates. * As the algorithm proceeds, two other sets get accumulated among this one set contains the candidates that have been already considered and chosen while the other set contains the candidates that have been considered but rejected.

18. What is the Greedy approach?

The method suggests constructing solution through sequence of steps, each expanding partially constructed solution obtained so far, until a complete solution is reached. On each step, the choice must be • Feasible (satisfy problem constraints) • Locally optimal (best local choice among all feasible choices available on that step) • Irrevocable (once made, it can’t be changed)

19. What are the steps required to develop a greedy algorithm?

* Determine the optimal substructure of the problem. * Develop a recursive solution. * Prove that at any stage of recursion one of the optimal choices is greedy choice. Thus it is always safe to make greedy choice. * Show that all but one of the sub problems induced by having made the greedy choice are empty. * Develop a recursive algorithm and convert into iterative algorithm.

20. Define forest.

Collection of sub trees that are obtained when root node is eliminated is known as forest

Page 19: DAA Question Bank

21. Write the difference between the Greedy method and Dynamic

programming.

Greedy method Dynamic programming Only one sequence of decision is generated. Many numbers of decisions are

generated. It does not guarantee to give an optimal solution always.

It definitely gives an optimal solution always.

22. State the requirement in optimal storage problem in tapes.

Finding a permutation for the n programs so that when they are stored on the tape in this order the MRT is minimized.This problem fits the ordering paradigm.

23. State efficiency of prim’s algorithm.

O(|v|2) (WEIGHT MATRIX AND PRIORITY QUEUE AS UNORDERED

ARRAY) O(|E| LOG|V|) (ADJACENCY LIST AND PRIORITY QUEUE AS MIN-HEAP) 17. State Kruskal Algorithm. The algorithm looks at a MST for a weighted connected graph as an acyclic subgraph with |v|-1 edges for which the sum of edge weights is the smallest.

24. State efficiency of Dijkstra’s algorithm.

O(|v|2) (WEIGHT MATRIX AND PRIORITY QUEUE AS UNORDERED

ARRAY) O(|E| LOG|V|) (ADJACENCY LIST AND PRIORITY QUEUE AS MIN-HEAP)

25. Differentiate subset paradigm and ordering paradigm

subset paradigm ordering paradigm At each stage a decision is made regarding whether a particular input is in an optimal solution (generating sub optimal solutions)

For problems that do not call for selection of optimal subset,in the greedy manner we make decisions by considering inputs in some order

Example kNAPSACK,MST Optimal storage on tapes

UNIT III - DYNAMIC PROGRAMMING

1. Give the Floyd’s algorithm

ALGORITHM Floyd(W[1..n,1..n]) //Implements Floyd’s algorithm for the all-pair shortest–path problem //Input: The weight matrix W of a graph //Output: The distance matrix of the shortest paths’ lengths

Page 20: DAA Question Bank

return D

2. Write the difference between the Greedy method and Dynamic

programming.

Greedy method Dynamic programming 1. Only one sequence of decision is generated. 1. Many number of decisions are

generated. 2. It does not guarantee to give an optimal solution always.

2. It definitely gives an optimal solution always.

3. Define dynamic programming.

Dynamic programming is an algorithm design method that can be used when a solution to the problem is viewed as the result of sequence of decisions. It is technique for solving problems with overlapping subproblems.

4. What are the features of dynamic programming?

• Optimal solutions to sub problems are retained so as to avoid recomputing of their values. • Decision sequences containing subsequences that are sub optimal are not considered. • It definitely gives the optimal solution always.

5. What are the drawbacks of dynamic programming?

• Time and space requirements are high, since storage is needed for all level. • Optimality should be checked at all levels.

6. Write the general procedure of dynamic programming.

The development of dynamic programming algorithm can be broken into a sequence of 4 steps. 1. Characterize the structure of an optimal solution. 2. Recursively defines the value of the optimal solution. 3. Compute the value of an optimal solution in the bottom-up fashion. 4. Construct an optimal solution from the computed information.

7. Define principle of optimality.

Page 21: DAA Question Bank

It states that an optimal solution to any of its instances must be made up of optimal solutions to its subinstances.

8. Define multistage graph

A multistage graph G =(V,E) is a directed graph in which the vertices are partitioned in to K>=2 disjoint sets Vi,1<=i<=k.The multi stage graph problem is to find a minimum cost paths from s(source ) to t(sink) Two approach (forward and backward)

9. Define All pair shortest path problem

Given a weighted connected graph, all pair shortest path problem asks to find the lengths of shortest paths from each vertex to all other vertices.

10. Define Distance matrix

Recording the lengths of shortest path in n x n matrix is called Distance matrix(D)

11. Define floyd’s algorithm

To find all pair shortest path The algorithm computes the distance matrix of a weighted graph with n vertices through series of n by n matrices: D(0)…D(k-1),D(k)…..D(n)

12. State the time efficiency of floyd’s algorithm

O(n3) It is cubic

13. Define OBST

Dynammic pgmg. Used If probabilities of searching for elements of a set are known then finding optimal BST for which the average number of comparisons in a search is smallest possible.

14. Define catalan number

The total number of binary search trees with n keys is equal to nth catalan number C(n)=(2n to n) 1/(n+1) for n>0,c(0)=1

15. State time and space efficiency of OBST

SPACE EFFICIENCY: QUADRATIC TIME EFFICIENCY: CUBIC.

Page 22: DAA Question Bank

UNIT IV - BACKTRACKING

1. What is backtracking?

Backtracking constructs solutions one component at a time and such partially constructed solutions are evaluated as follows

If a partially constructed solution can be developed further without violating the problem’s constraints, it is done by taking the first remaining legitimate option for the next component.

If there is no legitimate option for the next component, no alternatives for the remaining component need to be considered. In this case, the algorithm backtracks to replace the last component of the partially constructed solution with its next option.

2. What is a state space tree?

The processing of backtracking is implemented by constructing a tree of choices being made. This is called the state-space tree. Its root represents a initial state before the search for a solution begins. The nodes of the first level in the tree represent the choices made for the first component of the solution; the nodes in the second level represent the choices for the second component and so on.

3. What is a promising node in the state-space tree?

A node in a state-space tree is said to be promising if it corresponds to a partially constructed solution that may still lead to a complete solution.

4. What is a non-promising node in the state-space tree?

A node in a state-space tree is said to be promising if it corresponds to a partially constructed solution that may still lead to a complete solution; otherwise it is called non-promising.

5. What do leaves in the state space tree represent? Leaves in the state-space tree represent either non-promising dead ends or complete solutions found by the algorithm.

6. What is the manner in which the state-space tree for a backtracking algorithm is

constructed? In the majority of cases, a state-space tree for backtracking algorithm is constructed in the manner of depth-first search. If the current node is promising, its child is generated by adding the first remaining legitimate option for the next component of a solution, and the processing moves to this child. If the current node turns out to be non-promising, the algorithm backtracks to the node’s parent to consider the next possible solution to the problem, it either stops or backtracks to continue searching for other possible solutions.

7. What is n-queens problem?

Page 23: DAA Question Bank

The problem is to place ‘n’ queens on an n-by-n chessboard so that no two queens attack each other by being in the same row or in the column or in the same diagonal.

8. Draw the solution for the 4-queen problem.

9. What is the subset-sum problem? Find a subset of a given set S={s1,………,sn} of ‘n’ positive integers whose sum is equal to a given positive integer ‘d’.

10. When can a node be terminated in the subset-sum problem? The sum of the numbers included are added and given as the value for the root as s’. The node can be terminated as a non-promising node if either of the two equalities holds:

11. How can the output of a backtracking algorithm be thought of?

The output of a backtracking algorithm can be thought of as an n-tuple (x1, …xn) where each coordinate xi is an element of some finite linearly orderedsetSi. If such a tuple (x1,…xi) is not a solution, the algorithm finds the next element in Si+1 that is consistent with the values of (x1, …xi) and the problem’s constraints and adds it to the tuple as its (I+1)st coordinate. If such an element does not exist, the algorithm backtracks to consider the next value of xi, and so on.

12. Give a template for a generic backtracking algorithm.

ALGORITHM Backtrack(X[1..i]) //Gives a template of a generic backtracking algorithm //Input X[1..i] specifies the first I promising components of a solution //Output All the tuples representing the problem’s solution

13. What are the tricks used to reduce the size of the state-space tree? The various tricks are

Page 24: DAA Question Bank

Exploit the symmetry often present in combinatorial problems. So some solutions can be obtained by the reflection of others. This cuts the size of the tree by about half.

Preassign values to one or more components of a solution Rearranging the data of a given instance.

14. What is the method used to find the solution in n-queen problem by symmetry?

The board of the n-queens problem has several symmetries so that some solutions can be obtained by other reflections. Placements in the last n/2 columns need not be considered, because any solution with the first queen in square (1,i), n/2 <i<n can be obtained by reflection from a solution with the first queen in square (1,n-i+1)

15. What are the requirements that are needed for performing Backtracking?

To solve any problem using backtracking, it requires that all the solutions satisfy a complex set of constraints. They are: i. Explicit constraints. ii. Implicit constraints.

16. Define explicit constraint.

They are rules that restrict each xi to take on values only from a give set. They depend on the particular instance I of the problem being solved. All tuples that satisfy the explicit constraints define a possible solution space.

17. Define implicit constraint.

They are rules that determine which of the tuples in the solution space of I satisfy the criteria function. It describes the way in which the xi must relate to each other.

18. Define state space tree.

The tree organization of the solution space is referred to as state space tree.

19. Define state space of the problem. All the paths from the root of the organization tree to all the nodes is called as state space of the problem

20. Define answer states. Answer states are that solution states s for which the path from the root to s defines a tuple that is a member of the set of solutions of the problem.

21. What are static trees? The tree organizations that are independent of the problem instance being solved are called as static tree.

22. What are dynamic trees? The tree organizations those are independent of the problem instance being solved are called as static tree.

Page 25: DAA Question Bank

23. Define a live node.

A node which has been generated and all of whose children have not yet been generated is called as a live node.

24. Define a E – node.

E – Node (or) node being expanded. Any live node whose children are currently being generated is called as a E – node.

25. Define a dead node. Dead node is defined as a generated node, which is to be expanded further all of whose children have been generated.

26. What are the factors that influence the efficiency of the backtracking

algorithm? The efficiency of the backtracking algorithm depends on the following four factors. They are: i. the time needed to generate the next xk ii. The number of xk satisfying the explicit constraints. iii. The time for the bounding functions Bk iv. The number of xk satisfying the Bk

27. State 8 – Queens’s problem.

The problem is to place eight queens on a 8 x 8 chessboard so that no two queen “Attack” that is, so that no two of them are on the same row, column or on the diagonal.

28. State Sum of Subsets problem.

Given n distinct positive numbers usually called as weights , the problem calls for finding all the combinations of these numbers whose sums are m.

29. State m – colorability decision problem.

Let G be a graph and m be a given positive integer. We want to discover whether the nodes of G can be colored in such a way that no two adjacent nodes have the same color yet only m colors are used.

30. Define chromatic number of the graph. The m – colorability optimization problem asks for the smallest integer m for which the graph G can be colored. This integer is referred to as the chromatic number of the graph.

31. Define a planar graph.

A graph is said to be planar iff it can be drawn in such a way that no two edges cross each other.

Page 26: DAA Question Bank

32. What is promising and non-promising nodes? A node in a state space tree is said to be promising if it corresponds to a partially constructed solution from which a complete solution can be obtained. The nodes which are not promising for solution in a state space tree are called non-promising nodes.

UNIT V - BRANCH AND BOUND

1. What are the additional features required in branch-and-bound when compared to

backtracking? Compared to backtracking, branch-and-bound requires:

A way to provide, for every node of a state space tree, a bound on the best value of the objective function on any solution that can be obtained by adding further components to the partial solution represented by the node.

The value of the best solution seen so far 2. What is a feasible solution and what is an optimal solution?

In optimization problems, a feasible solution is a point in the problem’s search space that satisfies all the problem’s constraints, while an optimal solution is a feasible solution with the best value of the objective function.

3. When can a search path be terminated in a branch-and-bound algorithm? A search path at the current node in a state-space tree of a branch-and-bound algorithm can be terminated if

The value of the node’s bound is not better than the value of the best solution seen so far

The node represents no feasible solution because the constraints of the problem are already violated.

The subset of feasible solutions represented by the node consists of a single point in this case compare the value of the objective function for this feasible solution with that of the best solution seen so far and update the latter with the former if the new solution is better.

4. What is best-first branch-and-bound?

It is sensible to consider a node with the best bound as the most promising, although this does not preclude the possibility that an optimal solution will ultimately belong to a different branch of the state-space tree. This strategy is called best-first branch-and-bound.

5. What is knapsack problem?

Given n items of known weights wi and values vi, i=1,2,… ,n, and a knapsack of capacity W, find the most valuable subset of the items that fit the knapsack. It is convenient to order the items of a given instance in descending order by their value-to-weight ratios. Then the first item gives the best payoff per weight unit and the last one gives the worst payoff per weight unit.

Page 27: DAA Question Bank

6. Compare backtracking and branch-and-bound.

7. Give the formula used to find the upper bound for knapsack problem. A simple way to find the upper bound ‘ub’ is to add ‘v’, the total value of the items already selected, the product of the remaining capacity of the knapsack W-w and the best per unit payoff among the remaining items, which is vi+1/wi+1 ub = v + (W-w)( vi+1/wi+1)

8. What is the traveling salesman problem?

The problem can be modeled as a weighted graph, with the graph’s vertices representing the cities and the edge weights specifying the distances. Then the problem can be stated as finding the shortest Hamiltonian circuit of the graph, where the Hamiltonian is defined as a cycle that passes through all the vertices of the graph exactly once.

9. What are the strengths of backtracking and branch-and-bound? The strengths are as follows

It is typically applied to difficult combinatorial problems for which no efficient algorithm for finding exact solution possibly exist

It holds hope for solving some instances of nontrivial sizes in an acceptable amount of time

Even if it does not eliminate any elements of a problem’s state space and ends up generating all its elements, it provides a specific technique for doing so, which can be of some value.

10. Define Branch-and-Bound method.

The term Branch-and-Bound refers to all the state space methods in which all children of the E-node are generated before any other live node can become the E- node.

11. What are the searching techniques that are commonly used in Branch-and-

Bound method? The searching techniques that are commonly used in Branch-and-Bound method are: i. FIFO ii. LIFO

Page 28: DAA Question Bank

iii. LC iv. Heuristic search

12. What are NP- hard and Np-complete problems? The problems whose solutions have computing times are bounded by polynomials of small degree.

13. What is a decision problem?

Any problem for which the answer is either zero or one is called decision problem.

14. What is approximate solution?

A feasible solution with value close to the value of an optimal solution is called approximate solution.

15. Write formula for bounding function in Knapsack problem

In knapsack problem upper bound value is computed by the formula UB = v + (W-w) * (vi+1/wi+1)

16. Write about traveling salesperson problem.

Let g = (V, E) be a directed. The tour of G is a directed simple cycle that includes every vertex in V. The cost of a tour is the sum of the cost of the edges on the tour. The traveling salesperson problem is to find a tour of minimum cost. In branch and bound technique of TSP problem Lower bound lb= s/2

17. Write some applications of traveling salesperson problem.

-> Routing a postal van to pick up mail from boxes located at n different sites. -> Using a robot arm to tighten the nuts on some piece of machinery on an assembly line. -> Production environment in which several commodities are manufactured on the same set of machines.

18. Give the time complexity and space complexity of traveling salesperson

problem. Time complexity is O (n2 2n). Space complexity is O (n 2n).

19. Differentiate decision problem and optimization problem

Any problem for which the answer is either zero or one is called decision problem Any problem that involves the identification of an optimal (maximum or minimum) value of a given cost function is called optimization problem

20. What is class P and NP?

P is set of all decision problems solvable by deterministic algorithms in polynomial time. NP is set of all decision problems solvable by non deterministic algorithms in polynomial time.

Page 29: DAA Question Bank

21. Define NP-Hard and NP-Complete problems

Problem L is NP-Hard if and only if satisfiability reduces to L. A Problem L is NP-Complete if and only if L is NP-Hard and L belongs to NP.

Selected Questions from University Question Paper

PART A

1. Differentiate Time complexity from Space complexity. 2. What is an optimal solution? 3. Define Multistage Graphs. 4. Define Optimal Binary Search Tree. 5. Differentiate Explicit and Implicit Constraints. 6. What is the difference between a Live Node and a Dead Node? 7. What is a FIFO branch - and - bound algorithm? 8. How is the efficiency of an algorithm defined? 9. State the time complexity of bubble sort algorithm. 10. List out any two drawbacks of binary search algorithm. 11. What is an algorithm design technique? 12. Compare the order of growth n! and 2" . 13. How efficient is Prim's algorithm? 14. What is state space tree? 15. What are the additional items required for branch and bound compare

backtracking technique? 16. Define an algorithm. 17. What is a minimum cost spanning tree? 18. What is meant by optimal solution? 19. When do you say a tree as minimum spanning tree? 20. How will you construct an optimal binary search tree? 21. Define backtracking. 22. Write the procedure for selection sort. 23. State if backtracking always produces optimal solution. 24. Explain briefly branch and bound technique for solving problems. 25. Give the time efficiency and drawback of merge sort algorithm. 26. State the principle of backtracking.

PART B

1. With a suitable algorithm, explain the problem of finding the maximum and

minimum items in a set of n elements. (16 Marks) 2. Explain Merge Sort Problem using divide and conquer technique. Give an

example. (16 Marks) 3. Write down and explain the algorithm to solve all pairs shortest paths problem. 4. Describe the backtracking solution to solve 8- Queens problem. (16 Marks)

Page 30: DAA Question Bank

5. With an example, example Graph coloring Algorithm. (16 Marks) 6. With an example, explain how the branch - and - bound technique is used to solve

O/I knapsack problem. (16 Marks) 7. Define spanning tree. Discuss the design steps in Kruskal's algorithm to construct

minimum spanning tree with an example. (16) 8. Explain subset sum problem and discuss the possible solution strategies using

backtracking. (16) 9. Discuss the solution for Knapsack problem using branch and bound technique. 10. Write a pseudo code for divide and conquer algorithm for merging two sorted

arrays into a single sorted one. Explain with an example 11. Construct a minimum spanning tree using Kruskal's algorithm with your own

example. 12. Solve the all-pairs shortest-path problem for the diagraph with the weight matrix

given below :

13. Apply backtracking technique to solve the following instance of the subset sum problem. S = {1,3,4,5} and d =11.

14. Solve the following instance of the knapsack problem by the branch-and bound algorithm.

Item Weight Value 1 4 $40 2 7 $42 3 5 $25 4 3 $12

The Knapsack's capacity W = 10.

15. Write an algorithm to sort a set of 'N numbers using insertion sort. Trace the

algorithm for the following set of numbers: 20, 35, 18, 8, 14,41,3, and 39. 16. Write the Dijikstra's algorithm. 17. Explain KRUSKAL'S algorithm. 18. What is back tracking? Explain in detail. 19. What is branch and bound? Explain in detail. 20. Sort the following set of elements using Quick Sort.

12,24,8,71,4, 23, 6 21. Give a detailed note on divide and conquer techniques. 22. Write an algorithm for searching an element using binary search method. Give an

example.

Page 31: DAA Question Bank

23. Explain the method of finding the minimum spanning tree for a connected graph using Prim's algorithm. (16)

24. How will you find the shortest path between two given vertices using Dijkstra's algorithm? Explain. (16)

25. Describe the travelling salesman problem and discuss how to solve it using dynamic programming. (10)

26. Write short notes on n-Queen's problem. (6)

27. Discuss the use of Greedy method in solving Knapsack problem and subset-sum problem.

28. Write an algorithm for finding maximum element of an array. Perform best, worst and average case complexity with appropriate order notations.

29. Explain in detail quick sorting method. Provide a complete analysis of quick sort. 30. Explain in detail merge sort. Illustrate the algorithm with a numeric example.

Provide complete analysis of the same.

31. 1 3 4 4 5 6 5 6 2

8

Apply Prim's algorithm and Kruskal algorithm to the graph to obtain minimum spanning tree. Do these algorithms always generate same output - Justify.

32. Solve the following instance of the single-source shortest-paths problem with

vertex a as the source:

Write the algorithm, for the above problem.

33. Explain N-queens problem with an algorithm. Explain why back tracking is defined as a default procedure of last resort for solving problems.

34. Explain quick sort with an example. 35. Define spanning tree? Discuss the design steps in Prim’s algorithm to construct

minimum spanning tree with an example.

A

B

E

D

C

F

Page 32: DAA Question Bank

36. Explain sum of subset problem and discuss the possible solution strategies using backtracking.

37. Discuss the solution for traveling salesman problem using branch and bound technique.

TUTORIAL QUESTION I. Algorithm Efficiency:

Answer:

Page 33: DAA Question Bank

II. Sorting Problem 1 How will Merge Sort sort the 6 numbers:

40, 10, 20 , 18, 16,62. by divide and conquer technique. 2 Here are 16 integers: 22 36 6 79 26 45 75 13 31 62 27 76 33 16 62 47. Sort

them using a Quick Sort , Insertion Sort, Heap Sort, them as a pair of digits in a range of 0-9.

3 Sort the following set of elements using merge sort (10) 12,24,8,71,4,23,6,89,56

4 Trace the insertion sort algorithm for the following set of numbers. 20,35,18,8,14,41,3,39.

5 Sort the following elements using all the sorting methods:

i. 10, 5, 7, 6, 1, 4, 8, 3, 2, 9 ii. E X A M P L E

III. Shortest Distance Problem:

2. In the following Graph ,find out the shortest distance of all the nodes from the node A

.Explain with the help of suitable algorithms.

3. Solve the all-pairs shortest path problem for the digraph with the weight

matrix given below.

Page 34: DAA Question Bank

4. Solve the following instance of the single source shortest path problem with

vertex ‘a’ as the source. 4

5. Solve for following using Prim’s and Kruskal’s algorithm:

Ans:Prims 39 kruskals 9

6. Solve for following using Prim’s and Kruskal’s algorithm:

Ans: Prim15, Kruskals: E = {(1,3), (4,6), (2,5), (3,6), (3,4), (1,4), (2,3), (1,2), (3,5), (5,6) }

Page 35: DAA Question Bank

7. Solve for following using Prim’s and Kruskal’s algorithm:

Ans: 25 8. Solve for following using Prim’s and Kruskal’s algorithm:

Ans: 26 9. Floyd’s algorithm:

Ans:

A3 =

Page 36: DAA Question Bank

10. Dijikstra algorithm

Take source as 1 Ans: S = {1, 2, 4, 3, 5} IV. Optimal Binary search tree: 1. Key -5 1 8 7 13 21

Probabilities 1/8 1/32 1/16 1/32 1/4 1/2

2. Consider the following key sequence is and the probability sequence is .

Page 37: DAA Question Bank

3. Keys and Probabilities

key A B C D probability 0.1 0.2 0.4 0.3

C table i\j 0 1 2 3 4 1 0 0.1 0.4 1.1 1.7 2 0 0.2 0.8 1.4 3 0 0.4 1.0 4 0 0.3 5 0

V. Multistage graph: 1.

R table i\j 0 1 2 3 4 1 1 2 3 3 2 2 3 3 3 3 3 4 4 5

Page 38: DAA Question Bank

Ans: backward: 50---via the path 1-2-5-8-13-15 Forward: 50---via the path 1-2-5-8-12-15 or via the path 1-2-5-8-13-15 2.

Ans: 1-2-7-10-12 1-3-6-10-12

VI. Knapsack Problem:

1. Define Knapsack problem. Solve the following using Knapsack Problem n=3, m=20 (P1, P2, P3)= (24, 25, and 15) (W1, W2, W3)= (18, 15, and 10)

2. Let the capacity of the knapsack be 15 and the weights and profits are respectively

Profits 10 10 12 18 Volume 2 4 6 9

3. Knapsack Problem:

Item Weight Value 1 10 100 2 7 63 3 8 56 4 4 12

Take W=16 Ans: 2, 3

4. Item Weight Value 1 2 12 2 1 10 3 3 20 4 2 15

Take W=5 Ans: 1, 2, 4

1

2

3

4

5

6

7

8

9

10

11

12 s t 2

3

7

9 4

2 1 2

7

11

11

8 6

5 3

4 5 6

4

2

5

Page 39: DAA Question Bank

5. What are the four feasible solutions for n=3,m=20,(p1,p2,p3)=(25,24,15),(w1,w2,w3)=18,15,10).

VII. Sum of subset Problem: 1. Apply Backtracking technique to solve the following instance of the subset sum problem s=(1,3,4,5) & d=11

6. Solve 4 Queens Problem using Backtracking

VIII. Define Optimal Storage on Tapes. Solve the following using this technique:

n=3, (L1,L2,L3)=(5,10,3)

XI. Define the Traveling Salesperson Problem .Solve problem using TSP where the edge lengths are given as:

0 10 15 20 5 0 9 10 6 13 0 12 8 8 9 0