10
B.E./B.Tech. DEGREE EXAMINATION, NOVEMBER/DECEMBER 2011. Fourth Semester Computer Science and Engineering CS 2251 — DESIGN AND ANALYSIS OF ALGORITHMS (Regulation 2008) Time : Three hours Maximum : 100 marks Answer ALL questions. PART A — (10 × 2 = 20 marks) 1. What do you mean by linear search? 2. What is the properties of big-Oh notation. 3. What greedy algorithms? 4. What Knapsack problem? 5. What is traveling salesperson problem? 6. What do you mean by multistage graphs? 7. State the general backtracking method? 8. What is graph cloning? 9. What is spanning tree? Give an example. 10. What is NP Completeness? PART B — (5 × 16 = 80 marks) 11. (a) (i) Define Asymptotic notations. Distinguish between Asymptotic notation and conditional asymptotic notation. (10) (ii) Explain how the removing condition is done from the conditional Asymptotic notation with an example. (6) Or (b) (i) Explain how analysis of linear search is done with a suitable illustration. (10) (ii) Define recurrence equation and explain how solving recurrence equations are done. (6) 12. (a) What is divide and conquer strategy and explain the binary search with suitable example problem. Or (b) Distinguish between Quick sort and Merge sort, and arrange the following numbers in increasing order using merge sort. (18, 29, 68, 32, 43,37, 87, 24, 47, 50) 13. (a) (i) Explain the multistage graph problem with an example. (8) (ii) Find an optimal solution to the knapsack instance n = 7, m= 15 (p1, p2, p3, ….p7) = (10, 5, 15, 7, 6, 18, 3) and (w1, w2, w3, ... w7) (2, 3, 5, 7, 1, 4, 1) (8)

Design and Analysis of Algo

Embed Size (px)

Citation preview

Page 1: Design and Analysis of Algo

B.E./B.Tech. DEGREE EXAMINATION, NOVEMBER/DECEMBER 2011.Fourth Semester

Computer Science and EngineeringCS 2251 — DESIGN AND ANALYSIS OF ALGORITHMS

(Regulation 2008)Time : Three hours Maximum : 100 marks

Answer ALL questions.PART A — (10 × 2 = 20 marks)

1. What do you mean by linear search?2. What is the properties of big-Oh notation.3. What greedy algorithms?4. What Knapsack problem?5. What is traveling salesperson problem?6. What do you mean by multistage graphs?7. State the general backtracking method?8. What is graph cloning?9. What is spanning tree? Give an example.10. What is NP Completeness?

PART B — (5 × 16 = 80 marks)11. (a) (i) Define Asymptotic notations. Distinguish between Asymptotic notation and conditional asymptotic notation. (10)(ii) Explain how the removing condition is done from the conditional Asymptotic notation with an example. (6)

Or(b) (i) Explain how analysis of linear search is done with a suitable illustration. (10)(ii) Define recurrence equation and explain how solving recurrence equations are done. (6)12. (a) What is divide and conquer strategy and explain the binary search with suitable example problem.

Or(b) Distinguish between Quick sort and Merge sort, and arrange the following numbers in increasing order using merge sort. (18, 29, 68, 32, 43,37, 87, 24, 47, 50)13. (a) (i) Explain the multistage graph problem with an example. (8)           (ii) Find an optimal solution to the knapsack instance n = 7, m= 15 (p1, p2, p3, ….p7) = (10, 5, 15, 7, 6, 18, 3) and (w1, w2, w3, ... w7) (2, 3, 5, 7, 1, 4, 1) (8)

Or(b) Describe binary search tree with three traversal patterns? Give suitable example with neat diagram for all three traversal of binary search tree.. (16)14. (a) (i) How does backtracking work on the 8 Queens problem with suitable example? (8)(ii) Explain elaborately recursive backtracking algorithm? (8)

Page 2: Design and Analysis of Algo

Or(b) What is Hamiltonian problem? Explain with an example using backtracking. (16)

15. (a) Write a complete LC branch-and-bound algorithm for the job sequencing with deadlines problem. Use the fixed tuple size formulation. (16)

Or(b) Write a non-deterministic algorithm to find whether a given graph contains a Hamiltonian cycle. (16)

B.E./B.Tech. DEGREE EXAMINATION, APRIL/MAY 2011Fourth Semester

Computer Science and EngineeringCS 2251 — DESIGN AND ANALYSIS OF ALGORITHMS

(Regulation 2008)Time : Three hours Maximum : 100 marks

Answer ALL questionsPART A — (10 × 2 = 20 marks)

1. Using the step count method analyze the time complexity when 2 m × nmatrices are added.2. An array has exactly n nodes. They are filled from the set {0, 1, 2,...,n-1, n}.There are no duplicates in the list. Design an O(n) worst case time algorithm tofind which one of the elements from the above set is missing in the array.3. Show the intermediate steps when the numbers 123, 23, 1, 43, 54, 36, 75, 34are sorted using merge sort.4. Devise an algorithm to make a change for 1655 using the Greedy strategy. Thecoins available are {1000, 500, 100, 50, 20, 10, 5}.5. Write the difference between Greedy Method and Dynamic Programming.6. Write an algorithm to find the shortest path between all pairs of nodes.7. Define the chromatic number of a graph.8. Draw a graph with a cycle but with no Hamiltonian cycle.9. Define a strongly connected digraph and give the minimum in degree of all thenodes in the graph.10. Perform depth first and breadth first search on the following graph and

Page 3: Design and Analysis of Algo

find allthe nodes reachable from ‘a’.

PART B — (5 × 16 = 80 marks)11. (a) Write the recursive and non-recursive versions of the factorial function.Examine how much time each function requires as ‘n’ becomes large.Or(b) (i) Explain asymptotic notations in detail. (8)(ii) Write an algorithm for linear search and analyze the algorithm forits time complexity. (8)12. (a) Write an algorithm to perform binary search on a sorted list of elements.Analyze the algorithm for the best case, average case and worst case.Or(b) Using the divide and conquer approach to find the maximum andminimum in a set of ‘n’ elements. Also find the recurrence relation for thenumber of elements compared and solve the same.13. (a) Use function OBST to compute w(i, j), r(i, j), and c(i, j), 0<=i<j<=4, for theidentifier set ( ) 4 3 2 1 , , , a a a a = (cout, float, if, while) with p(1) = 1/20, p(2) =1/5, p(3) = 1/10, p(4) = 1/20, q(0) = 1/5, q(1) = 1/10, q(2) = 1/5, q(3) = 1/20,and q(4) 1/20. Using the r(i, j)’s, construct the optimal binary search tree.Or(b) Using dynamic approach programming, solve the following graph usingthe backward approach.14. (a) Using backtracking, find the optimal solution to a knapsack problem forthe knapsack instance n = 8, m = 110, (p1, p2. ... p7) = (11, 21, 31, 33, 43,53, 55, 65) and (w1, w2,...,w7) = (1, 11, 21, 33, 43, 53, 55, 65).Or(b) Write an algorithm for N QUEENS Problem and Trace it for n=6.15. (a) Write the Kruskal’s algorithm apply it to find a minimum spanning treefor the following graph :Or(b) Write short notes on NP-hard and NP-completeness.

Page 4: Design and Analysis of Algo

CS2251 DESIGN AND ANALYSIS OF ALGORITHMS NOVEMBER/DECEMBER 2010  ANNA UNIVERSITY QUESTION PAPER QUESTION BANK IMPORTANT

QUESTIONS 2 MARKS AND 16 MARKS

CS2251 DESIGN AND ANALYSIS OF ALGORITHMS NOVEMBER/DECEMBER 2010  ANNA UNIVERSITY QUESTION PAPER QUESTION BANK IMPORTANT

QUESTIONS 2 MARKS AND 16 MARKS

B.E./B.Tech. DEGREE EXAMINATION, NOVEMBER/DECEMBER 2010Fourth Semester

Computer Science and EngineeringCS 2251 — DESIGN AND ANALYSIS OF ALGORITHMS

(Regulation 2008)Time : Three hours Maximum : 100 Marks

Answer ALL questionsPART A — (10 × 2 = 20 Marks)

1. If 0 1 .... ) ( a n a n a n f mm + + = , then prove that ) ( ) ( m n O n f = .2. Establish the relationship between O and .3. Trace the operation of the binary search algorithm for the input –15, –6, 0, 7,9, 23, 54, 82, 101, 112, 125, 131, 142, 151, if you are searching for theelement 9.4. State the general principle of greedy algorithm.5. State the principle of optimality.6. Compare divide and conquer with dynamic programming and dynamicprogramming with greedy algorithm.7. Explain the idea behind backtracking.8. Define and solve the graph colouring problem.9. Define NP Hard and NP Completeness.10. What is a Minimum spanning tree?PART B — (5 × 16 = 80 Marks)11. (a) (i) Explain briefly the Time Complexity estimation, space complexityestimation and the trade off between Time and Space complexity. (6)(ii) Solve the following recurrence equations completely(1) ∑ −=≥ + = 1

Page 5: Design and Analysis of Algo

12 if , 1 ) ( ) (nin i T n T1 if , 1 ) ( = = n n T . (4)(2) ) 2 ( 6 ) 1 ( 5 ) ( − − − = n T n T n T (3)(3) n nnT n T lg22 ) ( + = . (3)

Or(b) (i) Write the linear search algorithm and analyse for its best, worstand average case time complexity. (10)(ii) Prove that for any two functions ) (n f and ) (n g , we have)) ( ( ) ( n g n f θ = if and only if )) ( ( ) ( n g O n f = and )) ( ( ) ( n g n f = . (6)12. (a) (i) Write a recursive algorithm to determine the max and min from agiven element and explain. Derive the time complexity of thisalgorithm and compare it with a simple brute force algorithm forfinding max and min. (10)(ii) For the following list of elements trace the recursive algorithm forfinding max and min and determine how many comparisons havebeen made.22, 13, –5, –8, 15, 60, 17, 31, 47. (6)Or(b) (i) Write the container loading greedy algorithm and explain. Provethat this algorithm is optimal. (8)(ii) Suppose you have 6 containers whose weights are 50, 10, 30, 20,60, 5 and a ship whose capacity is 100. Use the above algorithm tofind an optimal solution to this instance of the container loadingproblem. (8)13. (a) (i) Write and explain the algorithm to compute the all pairs source

Page 6: Design and Analysis of Algo

shortest path using dynamic programming and prove that it isoptimal (8)(ii) For the following graph having four nodes represented by thematrix given below determine the all pairs source shortest path (8)0 61 0 70 23 0∞ ∞∞∞ ∞∞ ∞Or(b) (i) Write the algorithm to compute the 0/1 knapsack problem usingdynamic programming and explain it. (8)(ii) Solve the following instance of the 0/1, knapsack problem given theknapsack capacity is W = 5 (8)Items Weight Value1 2 122 1 103 3 204 2 15 132  132  132 53099 314. (a) Write an algorithm to determine the Sum of Subsets for a given Sum anda Set of numbers. Draw the tree representation to solve the subset sumproblem given the numbers set as {3, 5, 6, 7, 2} with the Sum = 15. Deriveall the subsets. (8 + 8)Or(b) Write an algorithm to determine Hamiltonian cycle in a given graphusing back tracking. For the following graph determine the Hamiltoniancycle. (8 + 8)15. (a) Explain with an algorithm as to how 0/1 knapsack problem is solvedusing branch and bound technique. Apply branch and bound technique tosolve the following 0/1 knapsack instance if W = 10. (8 + 8)

Page 7: Design and Analysis of Algo

Items Weight Value1 4 402 7 423 5 254 3 12Or(b) Write an algorithm and explain to determine Biconnected Components.Prove the theorem that two biconnected components can have at mostone vertex as common and this vertex is an articulation point. (10 + 6)

B.E./B.Tech. DEGREE EXAMINATION, APRIL/MAY 2010Fourth Semester

Computer Science and EngineeringCS2251 — DESIGN AND ANALYSIS OF ALGORITHMS

(Regulation 2008)Time: Three hours Maximum: 100 Marks

Answer ALL QuestionsPART A — (10 × 2 = 20 Marks)

1. Differentiate Time Complexity from Space complexity.2. What is a Recurrence Equation?3. What is called Substitution Method?4. What is an Optimal Solution?5. Define Multistage Graphs.6. Define Optimal Binary Search Tree.7. Differentiate Explicit and Implicit Constraints.8. What is the difference between a Live Node and a Dead Node?9. What is a Biconnected Graph?10. What is a FIFO branch-and-bound algorithm?

PART B — (5 × 16 = 80 Marks)11. (a) Explain how Time Complexity is calculated. Give an example.Or(b) Elaborate on Asymptotic Notations with examples.12. (a) With a suitable algorithm, explain the problem of finding the maximumand minimum items in a set of n elements.Or(b) Explain Merge Sort Problem using divide and conquer technique. Give anexample.13. (a) Write down and explain the algorithm to solve all pairs shortest pathsproblem.

Page 8: Design and Analysis of Algo

Or(b) Explain how dynamic programming is applied to solve travellingsalesperson problem.14. (a) Describe the backtracking solution to solve 8-Queens problem.Or(b) With an example, explain Graph Coloring Algorithm.15. (a) Explain in detail the Graph Traversals.Or(b) With an example, explain how the branch-and-bound technique is used tosolve 0/1 knapsack problem.