9
IV/IV B.Tech (Regular) DEGREE EXAMINATION Design and Analysis of Algorithms (CS/IT 414) Scheme of Evaluation Maximum: 60 Marks 1. Write briefly about the following 1*12= 12 Marks a) Give the characteristics of an Algorithm? Ans: 1. Input, 2. Output, 3. Finiteness, 4. Definiteness, 5. Effectiveness. b) Give the control abstraction of Divide and Conquer. Ans: 1. Divide: The problem split into number of sub problems. 2. Conquer: The sub problems by solving recursively. 3. Combine: The solutions to the sub problems into the solution for the original problem. c) Define Adjacency List. Ans: A list from the graph, it indicates the adjacency nodes. d) Differentiate Greedy and Dynamic Programming. Ans: The main difference is in greedy the problem gets optimal solution, but in the dynamic each sub problem gets optimal solution. e) What is Articulation Point? Ans: If we are going to delete a point (or node) in the graph, then it is divided one graph into 2 or more sub graphs. The point is called Articulation Point. f) Give two applications of DFS. Ans: Finding strongly connected components, detecting cycles in the graph. g) Define E-node and live node. Ans: A node which has generated and all of whose children have not at been generated is called live node. The live node whose children are currently being generated is called E-node. h) Define cycle in the graph. Ans: The single path of length at least one that begins and ends at the same point. It’s exits in the directed graph. i) What is reliability and how reliability of a system increases? Ans: Reliability of a product is defined as the probability that the product will not fail throughout a prescribed operating period. Reliability increases if the number of components decreases. j) State sum of subsets problem. Ans: Finding sum of different combinations(from the set) of those elements in the given set is equal to the m(bag size).

60 Marks - Bapatla Engineering College

Embed Size (px)

Citation preview

IV/IV B.Tech (Regular) DEGREE EXAMINATION Design and Analysis of Algorithms (CS/IT 414)

Scheme of Evaluation Maximum: 60 Marks

1. Write briefly about the following 1*12= 12 Marks a) Give the characteristics of an Algorithm?

Ans: 1. Input, 2. Output, 3. Finiteness, 4. Definiteness, 5. Effectiveness.

b) Give the control abstraction of Divide and Conquer. Ans:

1. Divide: The problem split into number of sub problems. 2. Conquer: The sub problems by solving recursively. 3. Combine: The solutions to the sub problems into the solution for the original problem.

c) Define Adjacency List. Ans: A list from the graph, it indicates the adjacency nodes.

d) Differentiate Greedy and Dynamic Programming. Ans: The main difference is in greedy the problem gets optimal solution, but in the dynamic each sub problem gets optimal solution.

e) What is Articulation Point? Ans: If we are going to delete a point (or node) in the graph, then it is divided one graph into 2 or more sub graphs. The point is called Articulation Point.

f) Give two applications of DFS. Ans: Finding strongly connected components, detecting cycles in the graph.

g) Define E-node and live node. Ans: A node which has generated and all of whose children have not at been generated is called live node. The live node whose children are currently being generated is called E-node.

h) Define cycle in the graph. Ans: The single path of length at least one that begins and ends at the same point. It’s exits in the directed graph.

i) What is reliability and how reliability of a system increases? Ans: Reliability of a product is defined as the probability that the product will not fail throughout a prescribed operating period. Reliability increases if the number of components decreases.

j) State sum of subsets problem. Ans: Finding sum of different combinations(from the set) of those elements in the given set is equal to the m(bag size).

k) Define Brach and bound. Ans: The branch is going to happen with the satisfactory of the bound.

(or) The term Branch and Bound refers to all state space methods in which all the children of the e-node are generated before any live node becomes the e-node.

l) Define NP-hard problem. Ans: A problem is NP-hard if an algorithm for solving it can be translated into one for solving any NP-problem (nondeterministic polynomial time) problem. NP-hard therefore means at least as hard as any NP-hard problem.

UNIT- I

2. a) Define terms “Time complexity” and “Space complexity” of algorithms. Give a notation for expressing such a complexity and explain the features of such a notation. Ans: Time complexity: ----1.5 Mark The time complexity of an algorithm is the amount of computer time it needs to run to completion. Space complexity: ----1.5 Mark The space complexity of an algorithm is the amount of memory it needs to run to completion. Any one of Big-Oh, Omega and Theta notation with definition and example ------3 Marks Big-Oh:

The function f(n) =O(g(n)) iff there exist positive constants C & n0 such that f(n) ≤ C * g(n) for all n, n≥ n0.

Omega: The function f(n) = Ω (g(n)) iff there exist positive constants C & n0 such that f(n) ≥ C * g(n) for all n, n≥ n0.

Theta: The function f(n) = Ө(g(n)) iff there exist positive constants C1, C2 & n0 such that C1g(n) ≤ f(n)≤ C2 g(n) for all n, n≥ n0.

(Show as like for Big-Oh and Omega also)

2. b) Briefly explain Quick Sort Algorithm with suitable example and Derive its Time Complexity. Ans: Algorithm Qsort ( A,m,n) --------2 Marks integer i,j,k,t: if (m < n) i m; j n; k A(m) do do i i+1; while (A[i] <k) do j j-1; while ( A[j] >k) if ( i<j) t A[i]; A[i] A[j]; A[j] t; while (i>j) t A[m]; A[m] A[j]; A[j] t; Qsort ( A, m, j-1); Qsort (A, j+1, n);

Time complexity:---2 Marks T(n) = 2T(n/2) + αn = 2(2T (n/4) + αn/2) + αn = 22T (n/4) + 2αn (By simplifying and grouping terms together). = 22 (2T (n/8) + αn/4) + 2αn = 23T (n/8) + 3αn = 2kT (n/2 k) + kαn (Continuing likewise till the k th step)

Notice that this recurrence will continue only until n = 2k (otherwise we have n/2k < 1), i.e. until k = log n. Thus, by putting k = log n, we have the following equation:

T(n) = nT(1) + αn log n, which is O(n log n).

Example ----2 Marks

3. a) Explain the pseudo code conventions for writing an algorithm. Ans:

1. Comments begin with // and continue until end of the line. 2. Blocks are indicated with matching braces & . A compound statement can be represented as a block.

The body of s procedure alo forms a block. Statements are delimited by ;. 3. An identifier begins with a letter. The data types of variables are not explicitly declared. The types will be

clear from the context. Whether a variable is global or local to procedure will also be evident from the context. We assume simple data types such as integer, char, float,…….. Compound data types can be formed with records.

4. Assignment of values to variable is done using assignment statement. <var>:= <expression>;

5. There are two Boolean values true & false. In order to produce these values, the logical operators and, or, not and the relational operators <, ≤, =, ≠, ≥, > are provided.

6. Elements of multi dimensional arrays are accessed using [ and ]. 7. The following looping statements are employed for, while, and repeat- until. 8. A conditional statement has following forms

if(condition ) then <statement> if(condition) then <statement-1> else <statement-2>

9. Input and output are done using the statements read and write. No format is used to specify the size of i/p or o/p quantities.

10. There is only one type of procedure: Algorithm. An algorithm consists of a heading and body . The heading takes the form: Algorithm <name of algorithm>(<parameters –list>) -------6 Marks

3. b) Explain strassen’s matrix multiplication with an example. Ans: Formulas:----3 Marks P= (a11+ a12) (b11+b22) Q= (a21+a22) b11 R= a11 (b12-b22) S= a22 (b21-b11) T= (a11+a12) b22 U= (a21-a11) (b11+b12) V= (a12-a22) (b21-b22) C11= P+S-T+V C12= R+T C21= Q+S C22= P+R-Q+U Example----3 Marks

UNIT - II 4. a) Define minimum cost spanning tree. State and explain Prim’s Minimum cost Spanning tree algorithm with an example.

Ans: Let G = (V, E) be an undirected connected weightage graph. A sub graph t= (V, E|) of G is a minimum total length spanning tree of G iff t is a tree. -----1 Mark

-----2 Marks

Example----3 Marks

4. b) What is Travelling Salesman Problem? Apply Dynamic Programming to solve Travelling Salesman Problem.

Ans: The travelling salesman problem is to find a tour of minimum cost. -----1 Mark Example: -----5 Marks. Input is as like Graph or Adjacency Matrix to relate a graph. 5. a) Explain single source shortest path problem and give the Dijkstra’s algorithm to solve single source shortest path problem. Ans: To determine the lengths of the shortest paths from one vertex V to each all other vertices in graph G. ----1 Mark Example: -----5 Marks The example is a directed weightage graph with connectivity from one vertex to all each other vertices.

5. b) Explain Longest Common Subsequence Problem with an example? Ans: In the given sequences x=x1, x2, …,xn., y= y1, y2,….,yn another sequence z=z1, z2, …,zn is a subsequence of x and y. Here z is a Longest Common Subsequence. To Obtain LCS the given rules can follow:-------3 Marks

Rule1: 0 if i=0, j=0 C[i.j]= C[i-1, j-1] if i, j= 0 & xi=yj Max (C[i, j-1], C[i-1, j]) if i, j ≥0 & xi ≠ yj Rule2: Xi=yj Then B[i,j]= if C[i-1, j] ≥ C[i, j-1] then B[i, j]= else B[i,j]= Example------3 Marks

UNIT - III 6. a) Give the Algorithm for DFS and Explain with an example. Ans:

-----3 Marks Example-----3 Marks 6. b) Write an Algorithm for N- Queens problem and solve the 4-Queens problem by using state space tree. Ans: Mainly N queens must place in the n x n chess board without attack each other. No two queens are on the same column, same row and same diagonal.

---------3 Marks Example: solution table-----1 Mark State Space Tree-----2 Marks 7. a) Explain with the help of an algorithm, the mechanism of identifying articulation points and Bi-Connected components in a graph. Ans:

------- 3Marks

Example ----3 Marks i) Find DFS for the graph. ii) Assign Depth First Numbers to The Depth First Spanning Tree. iii) Find Least Depth First Numbers to the nodes in the DFS. iv) Identify Articulation Points.

7. b) What is Backtracking? Explain how the knapsack problem is solved using backtracking. Ans: Backtracking is a general algorithm for finding all(or one) solutions to some computational problems, notably constraint satisfaction problems, that incrementally builds candidates to the solution and abandons each partial candidate c(backtrack) as soon as it determines that c cannot possibly be completed to a valid solution. (or) To apply backtracking method the desired solution must be expressable as an n-tuples. (x1,x2,……,xn) where xi are chosen from some finite set si. The problem to be solved requires finding one vector which maximizes/ minimizes or satisfies a criteria function. ------2 Marks The problems which are solved by backtracking method require that the solution satisfy a complex set of constraints. These constraints are divided in two classes

1. Implicit: Exact solution for the problem 2. Explicit: The solution space for the problem Example of knapsack problem. -------5 Marks

UNIT - IV

8. a) Draw the portion of the state space tree generated by LC Branch and Bound for the following knapsack problem: n=5 profits=(10, 15, 6, 8, 4) and corresponding weights=(4, 6, 3, 4, 2) and m=12. Ans: Solution with state space tree------- 8 Marks Find the profit of the knapsack bag fill with fraction (upper bound value) and without fraction (lower bound value) at each node of the state space tree.

8. b) Explain the principles of Control Abstractions for LC- search.

Ans: For speeding up the search process here need to intelligent ranking function for live nodes. Each time, the next E-node is selected on the basis of this ranking function. For this ranking function additional computation (normally cost) is needed to reach the answer node from the live node. LC-search is a kind of search in which least cost involved for reaching to answer node. At each E-node the probability of being an answer node is checked. BFS and D-search are special cases of LC search. An LC search with bounding functions in known as LC Branch and Bound search. The applications of LC Branch and Bound are 0/1 Knapsack problem and Travelling salesman problem. The search mainly based on the state space tree. To find upper bound value and lower bound value at the each node to get the ranking value to identify which node is least cost. ---------4 Marks

9. a) Find an optimal solution for a travelling sales person problem using branch & bound technique by choosing an example. Ans: To get the solution for the TSP have to follow:-----3 Marks Step1: Find out the reduced cost matrix from a given cost matrix. This can be obtained as follows:

1. Row reduction: Get minimum element from the each row and subtract with each element include which element get, do it all rows in the cost matrix. After applying subtraction add all of the minimum elements, then gets row wise reduction sum.

2. Column reduction: As like row reduction get minimum element from each column and subtract to each element and do it all columns. Add all of the elements, then gets column wise reduction sum. Cumulative Reduction Sum (r) = row wise reduction sum + column wise reduction sum

Step2: For starting node, cumulative reduction sum is as lower bound value and ‘∞’ is upper bound value a) If path of i, j is considered then change all entries in row I and column j of matrix A to ‘∞’. b) Set A(j, 1) to ‘∞’.(Assume starting node as 1) c) Apply row reduction and column reduction except for rows and columns containing ‘∞’, and find

cumulative reduction sum (r). And find the lower bound value with Ĉ(S)= Ĉ(R) + A(i, j) + r Here Ĉ(R) is indicates lower bound of ith node in (i, j) path Ĉ(S) is indicates lower bound of jth node in (i, j) path r is cumulative reduction sum of the cost matrix in the (i, j) path. Example-----5 Marks

9. b) Explain the principles of FIFO Branch and Bound. Ans: FIFO stands or First In First Out, is follows the BFS technique. As like BFS, In this FIFO Branch and Bound reach a node to find upper bound and lower bound values and next it reaches another node in the same level of state space tree. And next reaches the node which is presented in the queue. FIFO Branch and Bound applications are knapsack problem and travelling salesman problem. This FIFO is one of the techniques of LC– search. When implementing a FIFO branch and bound algorithm, here reach each and every node in the state space tree. Here can find out more than one solution for the problem, if the problem has the multiple paths of solution. Unlike LCBB, The FIFO BB needs more memory to show each node in the state space tree. The main principle of the FIFO is reaching every node which is generated by solution process in the state space tree. -------------4 Marks Scheme prepared by Signature of the HOD, IT Dept. Paper Evaluators:

S.No Name Of the College Name of the Faculty Signature