DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING...

40
M.AARTHI Mahalakshmi Engineering College Page 1 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK UNIT-IV SUB CODE: CS2251 DEPT: CSE SUB NAME: DESIGN AND ANALYSIS OF ALGORITHMS SEM/YEAR: III/ II PART A (2 Marks) 1. What is the difference between explicit constraints and implicit constraints?(AUC MAY 2010/ MAY 2012 / DEC 2012 / DEC 2013) Implicit constraints are constraints that will be satisfied by the manner in which the branch-bound algorithm is constructed. Explicit constraints, however, are defined to be constraints that will require procedures for recognition as an integral part of the branch- and bound algorithm. 2. What is the difference between a Live Node and a Dead Node? (AUC MAY 2010) Live node: A node which is not yet expanded. Dead node: A node from which expansion is not possible, only backtracking can be done. 3. Explain the idea behind backtracking. Define the basic principles of back tracking. (AUC DEC 2010/ JUN 2012) The basic idea of backtrack is to build the solution tuple element by element and test whether the set being formed will result in success/ failure. The advantage of this method is that if at point of time the partial solution may result in failure, then the remaining tests pertaining to that set are ignored. 4. Define and solve the graph coloring problem?What is a Graph Coloring? What is meant by Graph Coloring Strategy? (AUC JUN 2010/ DEC 2010/DEC 2011 / DEC 2012) The m- coloring problem concerns finding all ways to color an undirected graph using at most m different colors, so that no two adjacent vertices are the same color. We usually call the m- Coloring Problem a unique problem for each value of m. 5. What is Hamiltonian path? (AUC JUN 2010/ DEC 2010) Hamiltonian path or traceable path is a path in an undirected graph which visits each vertex exactly once. 6. What is meant by planar graph? (AUC DEC 2010)

Transcript of DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING...

Page 1: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 1

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

QUESTION BANK

UNIT-IV

SUB CODE: CS2251 DEPT: CSE

SUB NAME: DESIGN AND ANALYSIS OF ALGORITHMS SEM/YEAR: III/ II

PART – A (2 Marks)

1. What is the difference between explicit constraints and implicit constraints?(AUC MAY

2010/ MAY 2012 / DEC 2012 / DEC 2013)

Implicit constraints are constraints that will be satisfied by the manner in which

the branch-bound algorithm is constructed.

Explicit constraints, however, are defined to be constraints that will require

procedures for recognition as an integral part of the branch- and – bound

algorithm.

2. What is the difference between a Live Node and a Dead Node? (AUC MAY 2010)

Live node: A node which is not yet expanded.

Dead node: A node from which expansion is not possible, only backtracking can

be done.

3. Explain the idea behind backtracking. Define the basic principles of back tracking.(AUC

DEC 2010/ JUN 2012)

The basic idea of backtrack is to build the solution tuple element by element and

test whether the set being formed will result in success/ failure.

The advantage of this method is that if at point of time the partial solution may

result in failure, then the remaining tests pertaining to that set are ignored.

4. Define and solve the graph coloring problem?What is a Graph Coloring? What is meant

by Graph Coloring Strategy? (AUC JUN 2010/ DEC 2010/DEC 2011 / DEC 2012)

The m- coloring problem concerns finding all ways to color an undirected graph using

at most m different colors, so that no two adjacent vertices are the same color.

We usually call the m- Coloring Problem a unique problem for each value of m.

5. What is Hamiltonian path? (AUC JUN 2010/ DEC 2010)

Hamiltonian path or traceable path is a path in an undirected graph which visits

each vertex exactly once.

6. What is meant by planar graph? (AUC DEC 2010)

Page 2: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 2

A graph is called planar if it can be drawn in a plane in such a way that no two

edges cross each other.

7. What do you mean by chromatic number of the graph? Define the chromatic number of a

graph. (AUC DEC 2010/ MAY 2011)

The chromatic number of G, denoted x(G), is the smallest number of colors

needed to color G (i.e) ( the smallest k such that there exists a coloring C for G and |C(

V)| =K

8. Draw a graph with a cycle but no Hamiltonian cycle. (AUC MAY 2011)

9. State the general backtracking method? (AUC DEC 2011)

The general method of Backtracking assumes that all answer nodes have to be

found.

Let (x1,x2,…,xi) be a path from root node to a problem state.

Let (x1,x2,…,xi) represent the set of all possible values for(xi+1) Such that (x1,x2,…,xi+1)

is a path of problem state.

Bi+1is a bounding function such that,Bi+1(x1,x2,…,xi+1) is false if that path does not lead

to an answer state and hence backtracking to the previous node is done.

10. Define Knapsack problem.

Given n positive weights wi, n positive profits pi, and a positive number m that is the

knapsack capacity. Then choose a subset of the weights such that,

∑ wixi<=m

∑ pi xi is maximized

The xi’s constitute a zero-one-valued vector. The solution space contains 2n distinct

ways to assign zero or one the xi’s. Two possible tree organizations are possible for

the solution space one to the fixed tuple size and other to the variable tuple size

formulation.

11. Define 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’.

12. Write the applications of graph coloring problem.

The famous case of the m-coloring decision problem is the 4- color problem for

planar graphs.

Given map, the regions in the map are colored such that no two adjacent regions

have the same color. Yet the number of colors needed is four only.

Page 3: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 3

Map is transformed into a graph. Each region of the map becomes a node. If the two

regions are adjacent in the map, then the corresponding nodes are joined by an

edge.

13. What is backtracking?

Find a solution by trying one of several choices.

If the choice proves incorrect, computation backtracks or restarts at the point of

choice and tries another choice.

It is often convenient to maintain choice points and alternate choices using

recursion.

14. What is 8-queens problem?

It is a classic combinatorial problem that place eight queens on an 8 x 8

chessboard so that no two attack, i.e., no two of them are on the same row,

column, or diagonal.

15. What is solution space?

Tuples that satisfy the explicit constraints define a solution space.

The solution space can be organized into a tree.

16. What is bounding function?

Bounding function is a function used to kill live nodes without generating all their

children.

17. What are the different ways of tree organization?

Backtracking

Backtracking is depth first node generation with bounding functions.

Branch- and -bound

Branch- and –bound is a state generation method in which E-node

remains E-node until is dead.

18. State if backtracking always produces optimal solution.

Backtracking always produces optimal solution since backtracking is a

systematic way to go through all the possible configurations of a solution space

for the problem instance.

19. What are the four factors considered for finding efficiency of the backtracking algorithm?

Time to generate the next xk

Number of xk satisfying the explicit constraints.

Time for the bounding function Bk

Number of xk satisfying Bk

Page 4: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 4

20. What is a feasible 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.

21. What is Hamiltonian cycle in an undirected graph?

22. What is 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 an 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 for the first component of the solution, the nodes in the second level

at represent the choices for the second component and so on.

Static trees are ones for which tree organizations are independent of the problem

instances being solved

Fixed tuple size formulation

Tree organization is independent of the problem instances being solved.

Page 5: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 5

PART-B (16 Marks)

1. Describe the backtracking solution to solve 8-Queens problem. (AUC MAY 2010)

Write down and explain the procedure for tackling the 8 – queens problem using a

Backtracking approach. (16) (AUC MAY 2012)

Page 6: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 6

Page 7: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 7

This shows how effective the backtracking approach of generating the state space tree

compared to the complete state space tree comprising of 69,281 nodes.

2. With an example, explain Graph Coloring Algorithm. (16) (AUC MAY 2010)

Explain the algorithm for finding all m-colorings of a graph.(16) (AUC MAY 2012)

Page 8: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 8

Page 9: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 9

Page 10: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 10

Page 11: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 11

3. Explain how backtracking technique works and apply it to 8-queens problem.(16)

(AUC MAY 2010)

Page 12: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 12

Page 13: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 13

Page 14: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 14

4. What is Knapsack problem? Explain how backtracking technique is used to solve

knapsack problem.(16) (AUC MAY 2010)

Page 15: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 15

Page 16: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 16

Page 17: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 17

Page 18: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 18

Page 19: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 19

Page 20: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 20

Page 21: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 21

5. Write an algorithm to determine the Sum of Subsets for a given Sum and a set of

numbers. Draw the tree representation to solve the subset sum problem given the

numbers set as {3, 5, 6, 7, 2} with the sum=15. Derive all the subsets. (16)

(AUC DEC 2010)

Explain subset-sum problem and discuss the possible solution strategies using

backtracking.(16) (AUC JUN 2007)

Page 22: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 22

Page 23: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 23

Page 24: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 24

Page 25: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 25

6. Write an algorithm to determine Hamiltonian cycle in a graph using backtracking. For the

following graph determine the Hamiltonian cycle. (AUC DEC 2010)

(or) Explain Hamiltonian cycles. (8) (AUC DEC 2012)

Explain the Hamiltonian circuit problem with algorithm and example.

Problem Statement:

CC

EE

A

F

B

DD

Page 26: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 26

Page 27: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 27

1+( n -1) + (n-1)2 + …… + ( n-1) n-1 = (n-1)n – 1 / n-2 7. Using backtracking, find the optimal solution to a knapsack problem for

the 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).(16) (AUC MAY 2011)

Page 28: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 28

Page 29: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 29

8. Write an algorithm for N QUEENS Problem and Trace it for n=6. (16) (AUC MAY 2011)

Page 30: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 30

Page 31: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 31

Page 32: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 32

Page 33: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 33

Page 34: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 34

Page 35: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 35

Page 36: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 36

Page 37: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 37

Page 38: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 38

9. How does backtracking work on the 8 Queens problem with suitable example? (8)

(AUC DEC2011)

Page 39: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 39

Page 40: DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING …mahalakshmiengineeringcollege.com/pdf/cse/IVsem/CS2251/UNIT_4.pdf · Backtracking Backtracking is depth first node generation with

M.AARTHI Mahalakshmi Engineering College Page 40

10. Explain elaborately recursive backtracking algorithm. (8) (AUC DEC2011)

11. What is backtracking? Explain in detail with n-queens problem.

Refer question No: 9