Вы находитесь на странице: 1из 35

SHAHEED UDHAM SINGH COLLEGE OF ENGG.

& TECHNOLOGY, TANGORI (MOHALI)

Department of Computer Science and Engineering

COURSE FILE
DESIGN & ANALYSIS OF ALGORITHMS
CS - 307 5TH SEM C.S.E

Teacher: Er. Gurjot Singh Sodhi

July - November 2012

Course File - Design & Analysis of Algorithms

RATIONALE :
Informally, an algorithm is any well-dened computational procedure that takes some value, or set of values, as input and produces some value, or set of values, as output. An algorithm is thus a sequence of computational steps that transform the input into the output. We can also view an algorithm as a tool for solving a well-specied computa-tional problem. The statement of the problem species in general terms the desired input/output relationship. The algorithm describes a specic computational proce- dure for achieving that input/output relationship. For example, one might need to sort a sequence of numbers into non decreasing order. This problem arises frequently in practice and provides fertile ground for introducing many standard design techniques and analysis tools. Here is how we formally dene the sorting problem:

Input: A sequence of n numbers a1 , a2 , . . . , an . Output: A permutation (reordering) a1 , a2 , . . . , an of the input sequence such that a1 a2 an .

For example, given the input sequence 31, 41, 59, 26, 41, 58, a sorting algorithm returns as output the sequence 26, 31, 41, 41, 58, 59. Such an input sequence is called an instance of the sorting problem. In general, an instance of a problem consists of the input (satisfying whatever constraints are imposed in the problem statement) needed to compute a solution to the problem. Sorting is a fundamental operation in computer science (many programs use it as an intermediate step), and as a result a large number of good sorting algorithms

Which algorithm is best for a given application depends onamong other factorsthe number of items to be sorted, the extent to which the items are already somewhat sorted, possible restrictions on the item values, and the kind of storage device to be used: main memory, disks, or tapes. An algorithm is said to be correct if, for every input instance, it halts with the correct output. We say that a correct algorithm solves the given computational problem. An incorrect algorithm might not halt at all on some input instances, or it might halt with an answer other than the desired one. Contrary to what one might expect, incorrect algorithms can sometimes be useful, if their error rate can be controlled.

An algorithm can be specied in English, as a computer program, or even as a hardware design. The only requirement is that the specication must provide a precise description of the computational procedure to be followed.
2|Page

Course File - Design & Analysis of Algorithms

What kinds of problems are solved by algorithms? Sorting is by no means the only computational problem for which algorithms have been developed. (You probably suspected as much when you saw the size of this book.) Practical applications of algorithms are ubiquitous and include the follow-ing examples:

The Human Genome Project has the goals of identifying all the 100,000 genes in human DNA, determining the sequences of the 3 billion chemical base pairs that make up human DNA, storing this information in databases, and devel-oping tools for data analysis. Each of these steps requires sophisticated algo-rithms. The savings are in time, both human and machine, and in money, as more information can be extracted from laboratory techniques.

The Internet enables people all around the world to quickly access and retrieve large amounts of information. In order to do so, clever algorithms are employed to manage and manipulate this large volume of data. Examples of problems which must be solved include nding good routes on which the data will travel (techniques for solving such problems ), and using a search engine to quickly nd pages on which particular information resides

1.1 Algorithms

Electronic commerce enables goods and services to be negotiated and ex-changed electronically. The ability to keep information such as credit card num-bers, passwords, and bank statements private is essential if electronic commerce is to be used widely. Public-key cryptography and digital signatures are among the core technologies used and are based on numerical algorithms and number theory.

In manufacturing and other commercial settings, it is often important to allo-cate scarce resources in the most benecial way. An oil company may wish to know where to place its wells in order to maximize its expected prot. A candidate for the presidency of the United States may want to determine where to spend money buying campaign advertising in order to maximize the chances of winning an election. An airline may wish to assign crews to ights in the least expensive way possible, making sure that each ight is covered and that government regulations regarding crew scheduling are met. An Internet service provider may wish to determine where to place additional resources in order to serve its customers more effectively.

3|Page

Course File - Design & Analysis of Algorithms

SYLLABUS

4|Page

Course File - Design & Analysis of Algorithms

CS - 307 DESIGN AND ANALYSIS OF ALGORITHMS External Marks: 60 L T P Internal Marks: 40 3 1 Total Marks: 100 PREREQUISITES: Discrete Structures and Data Structures. OBJECTIVES: Date Structures are an integral part of algorithm design and Discrete Structures covers topics like graph theory. COURSE CONTENTS: Models of computation. Algorithm analysis, order arithmetic, time and space complexities and average and worst case analysis, lower bounds. [L-8] Algorithm design techniques: divide and conquer, search and traversals. Dynamic programming. Backtracking. Branch and bound. [L-16] Sorting and searching algorithms, combinatorial algorithms, string processing algorithms. Algebraic algorithms, set algorithms. Hard problems and approximation algorithms. [L12] Problem classes P, NP, NP-hard and NP-complete, deterministic and non deterministic polynomial time algorithms., Approximation algorithms for some NP-complete problems. [L-6] TEXT BOOKS 1.V. Aho, J.E.Hopcroft, J.D. Ullman, design and Analysis of Algorithms, Addison Wesley, 1976. 2.Horowitz, S. Sahni, Fundamentals of Computer Algorithms, Galgotia Publishers, 1984. REFERENCES: 1. D.E.Knuth, The Art of Computer Programming, Vols. 1 and 3, Addison Wesley, 1968,1975. 2. K.Mehlhorn, Data Structures and Algorithms, Vols. 1 and 2, Springer Verlag, 1984. 3. Purdom, Jr.and C. A. Brown, The Analyses of Algorithms, Holt Rinechart and Winston, 1985.

5|Page

Course File - Design & Analysis of Algorithms

INDEX
S.NO TOPICS PAGE NO.

1 2 3 4 5 6 7

Time Table Assignments Sessionals Question Bank University Papers Viva Voice Questions Tutorial Sheet

7 9 11 16 23 28 34

6|Page

Course File - Design & Analysis of Algorithms

TIME TABLE
Period/Days Monday Tuesday Wednesday Thursday Friday LAB T 1 L L 2 3 4 LAB LAB LAB L L T 5 6 7 8 9

Period/Days Monday Tuesday Wednesday Thursday Friday

2 T

7 LAB

L L L L T

LAB LAB

LAB

7|Page

Course File - Design & Analysis of Algorithms

ASSIGNMENTS

8|Page

Course File - Design & Analysis of Algorithms

ASSIGNMENT 1 Q1 ) Explain all the Searching techniques. Q2 ) Explain all the Sorting techniques.

ASSIGNMENT 2 Q1) Solve 2nd Sessional Paper .

ASSIGNMENT 3 Q1) Explain P, NP Classes. Q2) Discuss Approximation Algorithms.

9|Page

Course File - Design & Analysis of Algorithms

SESSIONALS

10 | P a g e

Course File - Design & Analysis of Algorithms


Shaheed Udham Singh College of Engg & Technology,Tangori SESSIONAL TEST : 1 Subject : DAA Semester : 5th (A+B) Max Marks : 30 Max Time :11/2hrs

SECTION A Q 1 ) a. Is 2n+1=O(2n) ? Give reasons.

5 * 2 = 10 marks

b. The order of complexity of Binary Search in Best case is --------in the average case is -------in the worst case is ----------Q 2 ) How the time and space complexities measured for an algorithm? Q 3 ) What is the computing time for the following statement { for i=1to m do for i=1 to n do c[i,j]:= a[i,j]+ b[i,j]; } Q 4 ) What do you mean by the term Lower bound & Upper bound. Q 5 ) What do you mean by Growth of Functions.

SECTION B

2 * 5 = 10 marks

Q 1 ) Explain the use of asymptotic notations in the analysis of algorithms. Q 2 ) Explain an algorithm to insert 5 elements in a Stack and in a Queue.

Q 3 ) Solve the following expression 5*6+(5+(3/5+4)-1)*3/(5+2)


SECTION C 1*10 = 10 marks

Q 1 ) Write an algorithm for the following & calculate their Time Complexitya. Quick Sort b. Binary Search Q 2 ) Explain various Models of Computation.

11 | P a g e

Course File - Design & Analysis of Algorithms


Shaheed Udham Singh College of Engg & Technology,Tangori SESSIONAL TEST : 2 Subject : DAA Semester : 5th ( A & B ) Max Marks : 30 Max Time : 11/2 hrs

SECTION-A Q1. Define a) Cyclic interchange b) Minimum Spanning Tree Q2. What do you mean by Order Arithmetic? Q3. Differentiate between Krushkal Algorithm & Prims Algorithm? Q4. Differentiate between BFS& DFS? Q5.(a) Define lower bound & Upper bound. (b) Differentiate between Iteration and Recursion. SECTION-B

5*2=10

2*5=10

Q1. Given S<a,b,c,d,e,f> ; Probability(P)=<1,1,2,3,5,8>. Build binary tree according to Greedy Strategy. Q2. Explain Floyd-Warshall Algorithm with an example. Q3. Explain Knacksap Problem using Branch and Bound. Q4. Explain the Subset-Sum problem using the followingS=<3,4,5,6> ; X=9 SECTION-C Q1. Write a note on String Matching Algorithm? Q2. Starting from vertex V4, performa) BFS or DFS b) All spanning tree 1*10=10

12 | P a g e

Course File - Design & Analysis of Algorithms

Q3 From the given graph, draw a) Minimum Spanning Tree by Krushkal Algorithm b) Minimum Spanning Tree by Prims A8lgorithm c) Shortest Path from V1 to V

13 | P a g e

Course File - Design & Analysis of Algorithms


Shaheed Udham Singh College of Engg & Technology,Tangori SESSIONAL TEST : 3 Subject : DAA Semester : 5th ( A & B ) Max Marks : 30 Max Time : 11/2 hrs

SECTION A Q 1 ) (a) What is stable sorting? (b) Define Cooks Levin Theorm. Q 2 ) Given an example of an algorithm which is infinite in nature Q 3 ) What are Stored RAM model?

5 * 2 = 10 marks

Q 4 ) What is time complexity. What is the time complexity of Merge Sort? Q 5 )Name three conditions under which sequential search of a list is preferable to binary search. SECTION B 2 * 5 = 10 marks

Q 1 ) Differentiate between N-P Hard and N-P Complete problems with example. Q 2 ) Write a algorithm for (a) Quick sort. (b) Merge Sort Q 3 ) Explain the relationship between Turing Machine and RAM models. Q 4 ) Design an algorithm which finds number of words, lines and characters in a given text. Q 5 ) Write an algorithm for Knapsack problem using greedy method.

SECTION C Q 1 ) Write short note on following: (a) Techniques for algebraic problems. (b) Polynomial time algorithm.

1*10 = 10 marks

Q 2 ) What are approximation algorithms? Differentiate between deterministic and nondeterministic algorithms . Q 3 ) Among Merge sort, Insertion sort and Bubble sort which sorting technique is the best in worst case. Support your arguments with an example and analysis. 14 | P a g e

Course File - Design & Analysis of Algorithms

QUESTION BANK

15 | P a g e

Course File - Design & Analysis of Algorithms QUESTION BANK


1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. Differentiate between Binary and Binary Search Tree. Is 2n+1=O(2n)? What is the worst case running time of Quick Sort? What is the worst case running time of algorithm to delete each element from the linked list? Which is more efficient of BFS and DFS? What are maximum and minimum number of elements in a heap of height h? Where in a heap might the smallest element reside? Differentiate between NP Hard and NP Complete . What is time complexity ? What is space complexity? Give brief concept of Divide and conquer. Write an algorithm to sort an array containing 0's and 1's with complexity of order of n . What is recursion?What are its drawbacks? The order of complexity of Binary Search in Best case is -----in the average case is ------in the worst case is -------If W= MNOP,list all substrings of W. Define the term Divide and Conquer. How does heap Sort work? Explain the backtracking Problem with 4 Queens on a 4*4 chess board. Define non deterministic algorithm. Write an algorithm that will traverse a binary tree level by level. That is root is visited first then the intermediate children of root then grand children of root and so on. What are the advantages of dynamic programming over greedy method? What are the various techniques for design of various algorithms? How the time and space complexities measured for an algorithm? What is the order of Bubble Sort? What are the conditions under which backtracking can be used? What is Optimal Merge Pattern Problem? What is algorithm for in order traversal? What is solution space in Backtracking Techniques ? How will Merge Sort sort the 6 numbers: 40, 10, 20 , 18, 16,62. by divide and conquer technique.

30. What is Binary Search Tree? 31. What are various steps used in design of an algorithms?Give an example of algorithm which is infinite in nature. 32. What is the order of the computation for the following loop. for(i=1,i<n,i+1) for(j=1,j<n,j+1) 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. Give the definition for 0/1 knapsack problem. What are the various set operations possible? What is algorithm of Pre Order Traversal. What is NP Hard Problem? What is Ordering Paradigm? Differentiate between full and complete Binary Tree. Write an algorithm for insertion sort. Also give its computing time. What is lower bound? What are explicit and implicit constraints? What is algebraic simplification? 16 | P a g e

Course File - Design & Analysis of Algorithms


43. 44. 45. 46. 47. 48. How will u represent a polynomial using dense representation strategy. Differentiate between Deterministic and Non Deterministic algorithms. What is Criterion Function ? Define the Principal of Optimality. What are Decision Problems? What is Interpolation of polynomial? Short Answer Type Questions 49. Describe an algorithm to insert and delete edges in the adjacency list representation for an undirected graph .Remember that the edge (i,j) appears on the adjacency list for both vertex i and j 50. Give an algorithm to count number of leaf nodes in a Binary Tree t and what is its computing time 51. Explain basic concepts of NP hard and NP Complete problems. 52. Explain the use of asymptotic notations in the analysis of algorithms 53. What type of operations can be performed on string's .Explain at least 2 operations on strings with algorithms. 54. Write short notes on the following: (A)Dynamic Programming ( B) Branch and Bound 55. What do you mean by Time and space complexity. Among Quick Sort,Insertion Sort ,Heap Sort, Which algorithm is best to sort the data and why? 56. What are the disadvantages of Binary Search algorithm .What will be the order of complexity of a Binary Search in the unsuccessful case 57. 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,Bin Sort,treating them as a pair of digits in a range of 0-9. 58. Let G be a connected and undirected graph .Write an algorithm to find out minimum number of edges to be added to G so that G becomes disconnected .Your algorithm should output such a set of edges .What are time and space requirements of your algorithm 59. In the following Graph ,find out the shortest distance of all the nodes from the node A

.Explain with the help of suitable algorithms. 60. What is time and space complexity of Insertion Sort?Explain. 61. Write an string processing algorithm to identify whether a particular sequence of character is in string or not. 62. What are the various methods or techniques in which various algorithms can be expressed? 63. What is criterion function in backtracking?What is solution space for backtracking problem? Explain by taking sum of subset as a problem 64. What is LC Search. How does it help in finding a solution for Branch and Bound Algorithm. 17 | P a g e

Course File - Design & Analysis of Algorithms


65. Explain algorithm for evaluating a polynomial in coefficient exponent form. 66. What is 8 Queens problem?How does backtracking helps in solving it. 67. What is Greedy Method ?Write an algorithm for knapsack problem using Greedy Method. 68. What is Optimal Merge Pattern problem. Merge the files (X1,X2....X5 )of length 20,30,10,5,30 respectively. Also represent the merge pattern using Binary Tree. 69. Define Principal of Optimality. Explain 0/1 knapsack problem using Dynamic Programming. 70. What is evaluation and interpolation of Polynomials. Explain by giving a suitable example 71. Justify the statement An optimization problem can be solved in the polynomial time if and only if the corresponding decision problem can. 72. Explain the Big Oh notation used in the analysis of algorithm 73. What is the computing time for the following statement {for i=1to m do for i=1 to n do c[i,j]:= a[i,j]+ b[i,j]; } 74. Write an algorithm to delete an element from a linked list .Also mention the worst case running time for this operation. 75. Explain the connected and Biconnected components in Graphs. 76. Explain the tree traversal techniques. 77. Using suitable example explain straightforward evaluation of polynomials 78. Give brief concept of Algebraic Simplification and algebraic transformation 79. Explain the various path traversal techniques with example. 80. Define Algorithm and also explain the different criterion that all algorithms must satisfy. 81. Explain how to validate and analyze the algorithm . 82. Using the recursive algorithm ,explain how the tower of Hanoi problem can be solved. What will be time and space complexity for the algorithms. 83. Algorithm sum(a,n) { s=0.0; for i=1 to n do s=s+a[i]; return s ; } 84. Explain why we use a asymptotic notation .Also define the following notations (i)Big Oh (ii) Omega (iii)Theta 85. Explain an algorithm to insert 5 elements in stack and in a Queue. 86. Explain the different terminologies for tree and graph 87. Explain what do you mean by algebraic problem .Discuss various techniques for algebraic problems. 88. Define Prim's and Kruskal Algorithms 89. Explain Traveling Salesperson Problem 90. What do you mean by dynamic programming .Explain All pairs Shortest Path problem 18 | P a g e

Course File - Design & Analysis of Algorithms


with example Solve 4 Queens Problem using Backtracking What is dynamic Programming. What is Multi Stage Graph Problem What do you mean by sorting .What are various sorting Techniques .Explain any 2. Solve 0/1 knapsack Problem using Greedy Method. Solve 0/1 knapsack Problem using Dynamic Programming. Explain evaluation and interpolation with example. What is NP Hard and NP Complete ?Explain with example. Differentiate between Deterministic and Non Deterministic Algorithms. Explain the algorithm for Quick Sort .On what input does Quick Sort exhibit its worst case behavior 100. What is Multi Stage Graph Problem? How does dynamic problem help in solving it 101. Write short notes on (i) Approximation Algorithms (ii) Combinatorial Algorithms 91. 92. 93. 94. 95. 96. 97. 98. 99. 102)Write an algorithm to find nth minimum and maximum element using divide and conquer strategy 103)What is Traveling Salesperson Problem?.Find the solution of the following Traveling Salesperson Problem ?.Find the solution of the following salesman problem 104)calculate the number of swaps to sort the following data using bubble sort 5, 3, 2, 0, -4, -10, 15, 1 105)give pictorial representation of each pass. 106)What is criterion function and solution space of Backtracking? Explain and solve four Queen's problem using Backtracking 107)Explain in detail various Set algorithms 108)What is Greedy method? Give general algorithm for it. State and write Knapsack problem using Greedy Method 109)Give State space representation for 4 Queen's problem. Number the nodes as in (i)DFS (ii)BFS

110) Solve 15 Puzzle Problem using Branch and Bound .Initial arrangement of tiles is given below 111) Prove using the formal definition of Big O,(you need to give a ,c,,n0) 5n-3=O(n) 2n2+3n+20=O(n 2) 112) Prove using definition of Omega( you need to give a ,c,,n0) 3n-10=Omega(n) n2-5n-20=Omega(n 2) 113) By taking suitable example explain how the sum of Subset problem can be solved by using Backtracking algorithm design technique. 114) Explain the following algorithm design techniques ;

19 | P a g e

Course File - Design & Analysis of Algorithms


(i)Backtracking (ii)Branch and Bound (iii)Dynamic Programming (iv)Divide and Conquer 115) Write and explain the algorithms for Disjoint Set Union if we are given two sets Si and Sj 116) Define Knapsack problem. Solve the following using Knapsack Problem n=3,m=20 (P1,P2,P3)=(24,25,15) (W1,W2,W3)=(18,15,10) 117) Define Job Sequencing with Deadlines .Solve the following problem using Job Sequencing with Deadlines: n=4,(P1,P2,P3,P4)=(100,10,15,27) (D1,D2,D3,D4)=(2,1,2,1) 118) Define Optimal Storage on Tapes. Solve the following using this technique: n=3, (L1,L2,L3)=(5,10,3) 119) Define Optimal Merge Pattern .Find Optimal Merge pattern for 10 files whose lengths are 28,32,12,5,84,53,91,35,3,11 120) Obtain a set of Optimal Huffman Codes for the messages(M1........M7)with relative frequencies (q1....q7)=(4,5,7,8,10,12,20).Draw the decode tree for this set of codes. 121) Define the Traveling Salesperson Problem .Solve problem using TSP where the edge lengths are given as: 0 10 15 20 5 6 8 0 13 8 9 0 9 10 12 0

122) What do you mean by deterministic and Non Deterministic Algorithms. Differentiate between them. Write example for each of them. 123) Define NP Hard and NP Complete .Represent the relation between them. Prove that P is a subset of NP. 124) What is Clique Decision Problem. Show that clique optimization reduces to clique decision problem. 125) What are approximation Algorithms. Define absolute approximation and Eapproximation with example. 126) What is Algorithm .Write the various performance analysis techniques of Algorithm . 127) Discuss advantages and disadvantages of each 128) What is data structure ?Explain various data structures with examples 129) Write algorithm for Quick Sort using divide and Conquer . 130) What is Divide and Conquer algorithm. Use this algorithm to find maximum and minimum from a given array 131) Write an algorithm for Merge Sort using Divide and Conquer. 132) What do you mean by dynamic programming. Explain multistage Graphs using dynamic Programming 133) What are Strings. What are various String Algorithms. Explain any two of them. 20 | P a g e

Course File - Design & Analysis of Algorithms


134) Explain 0/1 knapsack problem using any two techniques you know 135) Explain asymptotic notations .Also explain the following notations: Big O Omega Theta 136) What do you mean by complexity of an algorithm .Define time and space complexity with examples 137) Explain various traversal techniques for trees 138) Explain various traversal techniques for graphs 139) What is Backtracking. Explain various problems solved by backtracking 140) What is Backtracking. Solve 8 Queens problem by backtracking 141) Explain various search techniques for trees 142) Explain various search techniques for graphs 143) How sum of subset problem is solved by Backtracking 144) What is graph coloring. Explain it with example .Show that a graph is 4 color able 145) What do you mean by Branch and Bound. Solve 15-puzzle problem 146) Define the following LC Search FIFO Branch and Bound LC branch and Bound 147) Define Principle of Optimality .Explain how does it holds on the following problems: knapsack Optimal Merge Pattern Shortest Path

21 | P a g e

Course File - Design & Analysis of Algorithms

UNIVERSITY QUESTION PAPERS

22 | P a g e

Course File - Design & Analysis of Algorithms


Design and Analysis of Algorithms (CS-307, Dec-07) Section-A 1). a). What do you understand by Algorithm Evaluation? b). What is asymptotic time complexity? c). What are Stored RAM model? d). Describe a path in an undirected graph. e). Define post order traversal of a tree. f). What is the time complexity of Merge Sort? g). Give an example of Dynamic Programming Approach. h). What are Union Find Problems? i). What is Pattern Matching? j). What is NP Complete Problem? Section-B 2). Explain the relationship between Turing Machine and RAM models. 3). Describe the Dynamic Programming algorithm for computing the minimum cost order of multiplying a string of n matrices M1 x M2 x M3.x Mn. 4). What are position trees? Describe using examples. 5). What are NP, NP Hard and NP complete problems? Explain by giving an example of each. 6). Explain the algorithm of a non-deterministic finite automation. Section-C 7). (a) Consider a Binary tree with names attached to the vertices. Write an algorithm to print the names in (i) Pre-order, (ii) Inorder, (iii) Post order. (b) How binary tree can be used for searching an element? Explain. 8). (a) What are string matching algorithms? (b) Given a text string x and pattern string y, determine all occurrences of y in x. 9). (a) Explain the algorithm for Fast disjoint set union algorithm. (b) Give an example of NP-Complete Problem.

23 | P a g e

Course File - Design & Analysis of Algorithms

Roll No. Total No. of Questions : 9

Total No. of Pages : 02

Paper ID [A 0467]
(Please fill this Paper ID in OMR Sheet)

B.Tech. (Sem. 5th) DESIGN AND ANALYSIS OF ALGORITHMS (CS - 307)


Time : 03 Hours Instruction to Candidates: 1) Section - A is Compulsory. 2) Attempt any Four questionsf rom Section- B. 3) Attempt any Tlvo questionsf iom Section- C. Maximum Marks : 60

Section - A QI) (10x2 =20) a) Define Big Omega Notation and Little Omega Notation . b) What is re-entrantp rogram? c) What is Akermann's function give example? d) What is the basic principal of Divide and Conquer? e) What is stable sorting? f) Differentiate between Top-down and Bottom-up approach. g) Define recurrencere lation. h) Given an example of an algorithm which is infinite in nature. i) Namet hreec onditionsu nderw hich sequentiasl earcho f a list is preferable to binarv search. j) What is an algorithm? Section - B (4x5=20) Q2)Differentiate betu'een N-P hard and N-P complete problems with example' Q3)Find lower bound for multiplying m x n matrix with n x 1 vector' Q4)Write a algorithm for Quick sort and complexity' Q5)Explain how the knapsack problem can be solved using branch and bound algorithms. Section- C (2x10=20) Q6)Find the shortest path from node 1 to all vertices of the graph given below' Show all the intermediates teps.T he numberso n the edgesa re the weights' Q7) Compare general and recursive back tracking methods and also write a algorithm to find all Hamiltoman cycle for graph using back tracking method. Q8) Deftne a minimum spanning tree. Write Prim's algorithm to find minimum spanning tree. Q9) Write short note on following: (a) Techniques for algebraic problems (b) Polynomial time algorithm.

24 | P a g e

Course File - Design & Analysis of Algorithms

Roll No. TotalN o. of Questions: 09 Total N o. of pages: 02 DESIGN AND ANALYSIS OF AI-GORITHMS SUBJECT CODE : CS - 307

Paper ID IA 0467l
Time : 03 Hours Maximum Marks : 60 Instruction to Candidates: 1) Section- A is Compulsory. 2) Attempt any Four questions from Section - B. 3) Attempt any Two questions from Section - C. Section - A QI) (10x2=20) a)Define Big oh Notation (O) and Little oh Notarion (o). I b) What is re-entrant program? c) What is NP complete? d) What are row major and column major ordering? e)What is the purpose ofAVL Tree? f)Differentiate between space complexity and Time space tradeoff. g) What is a solution space in the backtracking? h) Given an example o f an algorithm which is infinite in nature. i) Name the three conditions under which sequential search of a list is preferable to binary search. j) State the knapsack problem using branch and bound technique. Section - B (4x5:20) Q2) Does greedy algorithm always give an optimal solution?Give arguments to support your answer. Q3)Among Merge sort, Insertion sort and Bubble sort which sorting technique is the best in worst case. Support your arguments with an example and analysis. Q4) Write a recursive algorithm for Binary search Tree and complexity. Q5) What aret he featureso f brancha nd bounda lgorithms?D iscussi n detail. Section - C (2 x 10:20) Q6) Sortt he following usingG eapsortte chniqueL :'-5,9,20,8,4,100,11,3,3>0. Q7) (a) What are approximation algorithms?Explain approximation vertex cover. (b) Using Knuth-Marries-pratt algorithm find whether the pattern P : <0010> is in the text T - < 11 010 00010 10001010100 010 >. Q8) What do you mean by dynamic programming?Explain assignment problem with example. Q9) Define a minimum spanning tree. Write Kruskal's algorithm to find minimum Spanning tree.

25 | P a g e

Course File - Design & Analysis of Algorithms


Roll No. ...r.................. Total No. of Questions : 09

TotalN o. of Pages: 02

B. Tech.( Sem.- 5th)


DESIGN AND ANALYSIS OF ALGORITHMS SUBJECT CODE : CS - 307

Paper ID I IA0467l
[Note: Pleasefi ll subjectc odea nd paperI D on OMRI

Time : 03 Hours Instruction to Candidates: 1) Section - A is Compulsory. 2) Attempt any Four questions from Section - B. 3) Attempt any Two questions from Section - C. Section - A' QI) a) Explain the term the order of complexity. b) Give the general characteristics of greedy algorithm" c) Describe the general principle of Divide and conquer. d) Explain the asymptotic notation. e) What is re-entrant program? 0 What is stable sorting? g) Differentiate between NP-Hard and Np-Complete. h) What do you mean by worst case analysis? i) Define Non-deterministic algorithm. j) Give an xample of an algorithm which is infinite in nature.

Maximum Marks : 60

(10x2-20)

Section B (4 x.5 - 20) Q2) Differentiate between deterministic and non-deterministic algorithms? Q3) Explain how the knapsack problem can be solved using branch and bound algorithms. Q4) Explain the backtracking problem with the help of suitable example? Q5) Explain how to validate and analyze the algorithms. Q6) Explain the algorithm of a non-deterministic finite automation. Section-C (10x2-20) Q7) Explain in detail basic concepts of P, NP, NP-hard and NP-complete problems. Q8) Explain in detail the structure of string storage. Design an algorithm which finds number of words, lines and characters in a given text. Q9) What do you mean by complexity of an algorithm? Define time and space complexity with examples.

26 | P a g e

Course File - Design & Analysis of Algorithms

VIVA - VOICE QUESTION

27 | P a g e

Course File - Design & Analysis of Algorithms

1. What are the notations used in Evaluation of Arithmetic Expressions using prefix and postfix forms? Polish and Reverse Polish notations. 2. Convert the expression ((A + B) * C (D E) ^ (F + G)) to equivalent Prefix and Postfix notations. Prefix Notation: ^ - * +ABC - DE + FG Postfix Notation: AB + C * DE - - FG + ^ 3. Sorting is not possible by using which of the following methods? (a) Insertion (b) Selection (c) Exchange (d) Deletion (d) Deletion. 4. A binary tree with 20 nodes has 21 null branches?

Let us take a tree with 5 nodes (n=5)

Null Branches

It will have only 6 (ie,5+1) null branches. In general, A binary tree with n nodes has exactly n+1 null nodes. 5. What are the methods available in storing sequential files ? Straight merging, Natural merging, Polyphase sort, Distribution of Initial runs.

6. How many different trees are possible with 10 nodes ? 1014

28 | P a g e

Course File - Design & Analysis of Algorithms


For example, consider a tree with 3 nodes(n=3), it will have the maximum combination of 5 different (ie, 23 - 3 = 5) trees.

ii

iii

iv

In general: If there are n nodes, there exist 2n-n different trees.

7. In tree construction which is the suitable efficient data structure? (a) Array (b) Linked list (c) Stack (d) Queue (e) none (b) Linked list 8. What is the type of the algorithm used in solving the 8 Queens problem? Backtracking 9. There are 8, 15, 13, 14 nodes were there in 4 different trees. Which of them could have formed a full binary tree? 15. In general: There are 2n-1 nodes in a full binary tree. By the method of elimination: Full binary trees contain odd number of nodes. So there cannot be full binary trees with 8 or 14 nodes, so rejected. With 13 nodes you can form a complete binary tree but not a full binary tree. So the correct answer is 15. Note: Full and Complete binary trees are different. All full binary trees are complete binary trees but not vice versa 10. In the given binary tree, using array you can store the node 4 at which location?
1 2 4 5 3 29 | P a g e

Course File - Design & Analysis of Algorithms

At location 6 1 2 3 4 5

Root

LC1

RC1

LC2

RC2

LC3

RC3

LC4

RC4

where LCn means Left Child of node n and RCn means Right Child of node n 11. Sort the given values using Quick Sort? 65 70 75 80 85 60 55 50 45

Sorting takes place from the pivot value, which is the first value of the given elements, this is marked bold. The values at the left pointer and right pointer are indicated using L and R respectively. 65 70L 75 80 85 60 55 50 45R

Since pivot is not yet changed the same process is continued after interchanging the values at L and R positions

65

45

75 L

80

85

60

55

50 R

70

65

45

50

80 L

85

60

55 R

75

70

65

45

50

55

85 L

60 R

80

75

70

65

45

50

55

60 R

85 L

80

75

70

When the L and R pointers cross each other the pivot value is interchanged with the value at right pointer. If the pivot is changed it means that the pivot has occupied its original position in the sorted order (shown in bold italics) and hence two different arrays are formed, one from start of the original array to the pivot position-1 and the other from pivot position+1 to end.
30 | P a g e

Course File - Design & Analysis of Algorithms

60 L

45

50

55 R

65

85 L

80

75

70 R

55 L

45

50 R

60

65

70 R

80 L

75

85

50 L

45 R

55

60

65

70

80 L

75 R

85

In the next pass we get the sorted form of the array.

45

50

55

60

65

70

75

80

85

12. For the given graph, draw the DFS and BFS?

The given graph:

A X H E G P M J Y

BFS: DFS:

AXGHPEMYJ AXHPEYMJG

13. Of the following tree structure, which is, efficient considering space and time complexities? (a) Incomplete Binary Tree (b) Complete Binary Tree (c) Full Binary Tree

31 | P a g e

Course File - Design & Analysis of Algorithms


(b) Complete Binary Tree. By the method of elimination: Full binary tree loses its nature when operations of insertions and deletions are done. For incomplete binary trees, extra storage is required and overhead of NULL node checking takes place. So complete binary tree is the better one since the property of complete binary tree is maintained even after operations like additions and deletions are done on it.

14. What is a spanning Tree? A spanning tree is a tree associated with a network. All the nodes of the graph appear on the tree once. A minimum spanning tree is a spanning tree organized so that the total edge weight between nodes is minimized.

15. Does the minimum spanning tree of a graph give the shortest distance between any 2 specified nodes? No. Minimal spanning tree assures that the total weight of the tree is kept at its minimum. But it doesnt mean that the distance between any two nodes involved in the minimumspanning tree is minimum.

16. Convert the given graph with weighted edges to minimal spanning tree.

1
410 2

600 612 2985 1421

3
310

200

5
400

the equivalent minimal spanning tree is:


1

3 612 310 4 200 5

410 2

32 | P a g e

Course File - Design & Analysis of Algorithms

TUTORIAL SHEETS

33 | P a g e

Course File - Design & Analysis of Algorithms


TUTORIAL SHEET - 1
1. Is 2n+1=O(2n)? 2. What is the worst case running time of Quick Sort? 3. What is the worst case running time of algorithm to delete each element from the linked list? 4. What is time complexity ? 5. What is space complexity? 6. Explain asymptotic notations .Also explain the following notations: Big O Omega Theta 7. What is recursion?What are its drawbacks?

8. The order of complexity of Binary Search in Best case is -----in the average case is -----in the worst case is -------9. If W= MNOP,list all substrings of W. 10. What are the various methods or techniques in which various algorithms can be expressed?

TUTORIAL SHEET - 2
1. 2. 3. 4. 5. 6. Define the term Divide and Conquer. Explain the backtracking Problem with 4 Queens on a 4*4 chess board. What are the advantages of dynamic programming over greedy method? What are the conditions under which backtracking can be used? What is solution space in Backtracking Techniques ? How will Merge Sort sort the 6 numbers: 40, 10, 20 , 18, 16,62. by divide and conquer technique.

7. Give the definition for 0/1 knapsack problem. 8. In the following Graph ,find out the shortest distance of all the nodes from the node A

.Explain with the help of suitable algorithms. 9. Write an string processing algorithm to identify whether a particular sequence of character is in string or not. 10. What is criterion function in backtracking? What is solution space for backtracking problem? Explain by taking sum of subset as a problem

34 | P a g e

Course File - Design & Analysis of Algorithms


TUTORIAL SHEET 3
1. 2. 3. 4. 5. Define Prim's and Kruskal Algorithms What is NP Hard and NP Complete ?Explain with example. Differentiate between Deterministic and Non Deterministic Algorithms. What is Multi Stage Graph Problem? How does dynamic problem help in solving it Write short notes on (i) Approximation Algorithms (ii) Combinatorial Algorithms

6. Explain in detail various Set algorithms 7. Solve 15 Puzzle Problem using Branch and Bound .Initial arrangement of tiles is given below 8. Define Job Sequencing with Deadlines .Solve the following problem using Job Sequencing with Deadlines: n=4,(P1,P2,P3,P4)=(100,10,15,27) (D1,D2,D3,D4)=(2,1,2,1) 9. Define Optimal Storage on Tapes. Solve the following using this technique: n=3, (L1,L2,L3)=(5,10,3) 10. What is Clique Decision Problem. Show that clique optimization reduces to clique decision problem.

35 | P a g e

Вам также может понравиться