You are on page 1of 11

970 -SREE SOWDAMBIKA COLLEGE OF ENGINEERING Chettikurichi, Aruppukottai Sub. Code Sub.

Name : CS41 : Design and Analysis Of Algorithms CLASS TEST-1 1. What are asymptotic notations? Explain in detail.(Nov/Dec 2007)(6) 2. Derive the analysis (all cases) for linear search method.(Apr/May 2008)(10) CLASS TEST-2 3. Solve the homogeneous and inhomogeneous recurrence equation(12) 4. Give the smoothness rule applied for recurrence relation (Nov/Dec 2007) (2) 5. How efficiency of an algorithm is defined?(Nov/Dec 2007)(2) CLASS TEST-3 6. Write an algorithm to sort a given list of elements using merge sort. Show the operation of the algorithm on the list 38, 27, 43,3,9,82,10 (Apr/May 2008) (12) 7. List out any two drawbacks of binary search algorithm(Nov/Dec 2007) (2) 8. Write a pseudo code for a divide and conquer algorithm for finding the position of the largest element in an array of n numbers. (Nov/Dec 2008) (2) CLASS TEST-4 9. Explain Greedy approach to solve the knapsack problem. Find an optimal solution to the knapsack instance n=3, m=20, (p1,p2,p3)=(25,24,15) & (w1,w2,w3)=(18,15,10).(10) 10. Explain pseudo algorithm for container loading problem. Analyses your algorithm. (6) CLASS TEST-5 11. For the given digraph, obtain optimum cost Tour. (14) (Apr/May 2008) Year & Branch: II - CSE Staff In-charge: Ms.S.Vijaya Iswariya Lakshmi

10 13 1 5 6 15 8 12 3 9 4 9 20 8 10 2

(14) 12. Comparison between divide and conquer and dynamic programming (2)

CLASS TEST-6 13. Solve the all pair shortest path problem for the diagraph with the weighted matrix given below. a b c d a 0 2 6 b 0 7 c 3 0 d 1 0 (Nov/Dec 2006) (12)

14. Define traveling Salesperson problem (May/June 2009) (2)

CLASS TEST-7 15. Using Backtracking enumerate how can you solve the following problems. . (Nov/Dec 2008), (May/June 2007) Queens Problem. Hamiltonian Problem. (14)

16. State the principle of backtracking (Nov/Dec 2005) (2) CLASS TEST-8

17. Apply the backtracking technique to solve the following instance of the subset sum problem. (Apr/May 2008) & d=13. (12) CLASS TEST-9 19. Explain in detail about BFS and DFS (14) (Nov/Dec 2007), (Nov/Dec2008), (Nov/Dec2009), May/June 2007) 20. Define articulation point (Apr/May 2008) (2) CLASS TEST-10 21. Solve the following instance of the knapsack problem by branch and bound algorithm. . (Nov/Dec 2008) Item 1 2 3 4 (14) Weight 10 7 8 4 Values $100 $63 $56 $12 W=16 S= {3, 4, 5, 6}

18. What is graph coloring and write some applications? (4)

22. State the properties of NP Hard problems. (Apr/May2008) (2) CLASS TEST-1 Answer Key 1. Asymptoic Notations .Big Oh notation: (Asymptotic upper bound) T (n) = f (n) = O (g (n)) If f (n) <= c*g (n) for all n n0, where c & n0 are constants > 0 O (g (n)): class of functions f (n) that grow no faster than g (n) Big notation: (Asymptotic Tight Bound) T (n) = f (n) = (g (n)) If c1*g (n) <= f (n) <= c2*g (n) for all n > n0, where c1, c2 and n0 are Constants> 0. (g (n)): class of functions f (n) that grow at same rate as g (n) Big notation: (Asymptotic lower bound) T (n) = f (n) = (g (n)) If f (n) >= c*g (n) for all n > n0, where c and n0 are constants > 0 (g (n)): class of functions f (n) that grow at least as fast as g (n). 2Analysis of Linear Search. Best case time complexity It is time complexity algorithm runs for short time If the key element present at first location in the list (X [0.n-1]) then algorithm runs very short time. Cbest=1 Worst case time complexity

It is time complexity algorithm runs for long time If the key element present at nth location in the list (X [0.n-1]) then algorithm runs very long time. Average case time complexity It gives behavior of an algorithm on specific random input C avg (n)=Probability of unsuccessful search + Probability of successful search

CLASS TEST-2Answer Key 3. Recurrence Relations Homogenous Recurrence Relations Solve: Try Multiply by
x n = a 1 x n 1 + a 2 x n 2 +... + a d x n d

a0 0

xn = rn
rd rn

a0 0

Get characteristic equation:


r d a 1 r d -1 a 2 r d - 2 ... a d = 0

Case of Distinct Roots Distinct Roots r1, r2, , rd


x n = c i rin
i =1 d

x n ~ c i rin

Where ri is dominant root


ri >rj j i

Inhomogeneous Recurrence Equations


x n = a 1 x n 1 + a 2 x n 2 +... + a d x n+a0 d

Nonzero constant term Solution Method

a0 0

(1) Solve homogenous equation Yn = a1 Yn 1 + a 2 Yn 2 + ... + a n Yn d Case

=1

, add particular solution a x n = cn= 0 ia i n

3) Add particular and homogeneous solutions, and solve for constants 4. Smoothness of Recurrence relation Let T (n) be an eventually non decreasing function and f (n) be a smooth function. If T (n) (f (n)) for values of n that are powers of b, Where b>=2, then T (n) (f (n)) for any n. 5. Efficiency of an algorithm Time complexity - indicates how fast the algorithm runs Space complexity - indicates how much extra memory the algorithm needs. CLASS TEST-3Answer Key 6. Merge Sort The merge sort splits the list to be sorted into two equal halves, and places them in separate arrays. This sorting method is an example of the DIVIDE-AND-CONQUER paradigm The merge sort is a comparison sort and has an algorithmic complexity of O (n log n). Algorithm Refer Book 7. Drawbacks of Binary Search The disadvantage of a binary search tree is that its height can be as large as N-1 - This means that the time needed to perform insertion and deletion and many others Operations can be O (N) in the worst case a binary tree with N node has height at least (log N) 8. Algorithm Refer Book CLASS TEST-4Answer Key 9. Knapsack problem Given items of different values and volumes, find the most valuable set of items that fit in a knapsack of fixed volume. We have n kinds of items, 1 through n. Each kind of item j has a value pj and a weight wj. We usually assume that all values and weights are nonnegative. The maximum weight that we can carry in the bag is W. The most common formulation of the problem is the 0-1 knapsack problem, which restricts the number xj of copies of each kind of item to zero or one. Mathematically the 0-1-knapsack problem can be formulated as:

minimize

Subject to Algorithm Refer Book 10. Container loading problem In this problem, the ship is loaded attach stage, each container is loaded. The total weight of all the containers must be less than or equal to the capacity. The Greedy approach is applied to the problem for solving. CLASS TEST-5Answer Key 11. Optimum Tour Distance matrix 1 1 2 3 4 0 5 6 8 2 10 0 13 8 3 15 0 9 4 20 12 0

Algorithm Refer Book

Step 1: Select any arbitrary node say select 1 Let S= then, Cost (2, , 1) =d (2, 1) =5 Cost (3, , 1) =d (3, 1) =6 Cost (4, , 1) =d (4, 1) =8 Step 2: Candidate(S) =1 Apply formula Cost(i,S)=min { d[I,j] +Cost (j,s-{j}} Hence from vertex 2 to 1, Vertex 3 to 1 and vertex 4 to 1 calculate cost Cost (2, {3}, 1) =15 Cost (2, {4}, 1) =18 Cost (3, {2}, 1) =18 Cost (4, {2}, 1) =13 Cost (4, {3}, 1) =15 Step 3: Candidate(S) =2 Cost(2,{3,4},1)=min{ [d(2,3) +Cost (s,{4},1)],[d(2,4)+Cost(4,{3},1)]=25 Cost (3, {2, 4}, 1) =25 Cost (4, {2, 3}, 1) =23 Step 4: Candidate(S) =3 Cost (1, {2, 3, 4}, 1) =35 Optimum tour is: 1, 2,3,4,1 (Length is 35)

12. Comparison b/w Divide and Conquer and Dynamic Programming Sl.No The 1. Divide and Conquer problem is divided into Dynamic Programming small

subproblems.These sub problems are solved In dynamic programming many decision independly.Finally all the solutions of sub sequences are generated and all the overlapping problems are collected together to get the subinstances are considered. solution to the given problem In this method duplications in sub solutions 2. are neglected.i.e.,duplicate sub solutions may be obtained Divide and conquer is less efficient

In dynamic computing duplications in solutions is avoided totally. Dynamic programming is efficient than divide uses bottom up

3.

Because of rework on solutions and conquer strategy The divide and conquer uses top down Dynamic programming approach of problem

4.

solving(recursive approach of the problem solving(iterative

methods) method) Divide and conquer splits its input at Dynamic programming splits its input at every 5. specific deterministic points usually in the possible split pints it determines which split middle point is optimal.

CLASS TEST-6Answer Key 13.Distance Matrix

0 2 6 0 2 6 0 7 D(2)
=

0 7

3 0 D(1) =

1 0 0 2 9 6 0 7 3 5 0 9 1 0

D(0) =

3 0 9

1 0

0 2 9 6

10 0 7 16

3 5 0 9

4 6 1 0

0 2 7 6

10 0 7 16

3 5 0 9

4 6 1 0

D(3) =

D(4) =

14. Traveling Salesperson problem The goal of the Travelling Salesman Problem (TSP) is to find the cheapest tour of a select number of cities with the following restrictions: You must visit each city once and only once You must return to the original starting point CLASS TEST-7Answer Key 15. 8 Queens Problem. Place eight queens on an 8 8 chessboard so that no queen attacks another queen.

Identify data structures to solve the problem First pass: Define the chessboard to be an 8 8 array - Second pass: Since each queen is in a different row, define the chessboard solution to be an 8-tuple (x1, . . . , x8), where xi is the column for ith queen Identify explicit constraints Explicit constraints using 8-tuple formulation are Si = {1, 2, 3, 4, 5, 6, 7, 8}, 1i8 o Solution space of 88 - 8-tuples Identify implicit constraints o No two xi can be the same, or all the queens must be in different columns All solutions are permutations of the 8-tuple (1, 2, 3, 4, 5, 6, 7, 8)

Reduces the size of solution space from 88 to 8! tuples o No two queens can be on the same diagonal. The solution above is expressed as an 8-tuple as 4, 6, 8, 2, 7, 1, 3, 5

Algortihm Refer Book Hamiltonian circuit problem using Backtracking Let G = (V, E) be a connected graph with n vertices. A Hamiltonian cycle is a round trip path along n edges of G that visits every vertex once and returns to its starting position. Algorithm Refer Book 16. Backtracking Backtracking is a method in which the desired solution is expressed as n tuple (x1,x2,x3,x4,xn )which is chosen from solution space, using backtrack formulation. The solution obtained i.e. (x1,x2,x3,x4,xn) can either minimizes or maximizes or satisfies the criteria function.

CLASS TEST-8Answer Key 17.Backtracking technique to solve subset sum problem S= {3, 4, 5, 6} & d=13. 0 W/O 3 With 3 3 With 4 W/O 4 7 With 5 1 2 With 6 1 3 W/O 5 With 5 7 W/O 6 8 With 4 W/ O 4 0

3 W/ O 5 3

4 With 5 W/O 5

4 Solution = {3, 4, 6}

18. Graph Coloring and applications Graph coloring is the problem of coloring each vertex in a graph such that no two adjacent vertices are the same color Some direct examples: Map coloring Register assignment CLASS TEST-9Answer Key 19. BFS and DFS DFS (Depth First Search) - DFS implemented using stack - Applications of DFS are, Topological Sort Strongly Connected Components. Spanning Forest BFS (Breadth First Search) - BFS implemented using Queue - Applications of BFS are, Compute the connected components Compute a spanning forest Find shortest path. Diagram Refer Book 20. Articulation point A vertex v in a connected graph G is an articulation point if the deletion of vertex v together with all edges incident to v disconnects the graph into two or more non empty components. CLASS TEST-10Answer Key 21.Knapsack Problem-Solution Item 1 2 3 4 W=16 With 1 ub = v+ (W-w) * v(i+1)/ w (i+1) Weight 10 7 8 4 Values vi/wi $100 $63 $56 $12 10 9 7 3 w=0 v=0 ub=100 W/O 1 w=4 v=40 ub=76

w=0 v=0 ub=60

With 2

W/O 2

w=11

w=4 v=40 ub=70 W/O 3

With 3 w=9 v=65 ub=69 With 4 W/O 4 w=12 w=9 v=65 ub=65 22. Propertites of NP Hard Problems A problem H is NP-hard if and only if there is an NP-complete problem L that is Polynomial time. w=4 v=40 ub=64

You might also like