Department of Computer Science and Engineering
Department of Computer Science and Engineering
Department of Computer Science and Engineering
UNIT- V
UNIT- 5
COPING WITH THE LIMITATIONS OF ALGORITHM POWER
PART - A
1. Define Hamiltonian circuit problem [A/M15]
Hamiltonian circuit problem is defined as the problem of finding a Hamiltonian circuit.
Hamiltonian circuit is a circuit that visits every vertex exactly once and returns to the starting
vertex.
PART – B
1. State the subset-sum problem and Complete state-space tree of the backtracking
algorithm applied to the instance A={3, 5, 6, 7} and d=15 of the subset-sum problem.
[M-16]
The subset-sum problem finds a subset of a given set A = {a1. . . an} of n positive
Integers whose sum is equal to a given positive integer d.
For example, for A = {1, 2, 5, 6, 8} and d = 9, there are two solutions: {1, 2, 6} and {1,
8}. Of course, some instances of this problem may have no solutions.
It is convenient to sort the set‘s elements in increasing order. So, we will assume that
a1< a2 < . . . < an.
A = {3, 5, 6, 7} and d = 15 of the subset-sum problem. The number inside a node is the
sum of the elements already included in the subsets represented by the node. The
inequality below a leaf indicates the reason for its termination.
FIGURE Complete state-space tree of the backtracking algorithm applied to the instance
The state-space tree can be constructed as a binary tree like that in the instance A = {3, 5, 6,
7} and d = 15.
The root of the tree represents the starting point, with no decisions about the given elements
made as yet.
Its left and right children represent, respectively, inclusion and exclusion of a1 in a set being
sought. Similarly, going to the left from a node of the first level corresponds to inclusion of a2
while going to the right corresponds to its exclusion, and so on.
Thus, a path from the root to a node on the ith level of the tree indicates which of the first I
numbers have been included in the subsets represented by that node. We record the value of s,
the sum of these numbers, in the node.
If s is equal to d, we have a solution to the problem. We can either report this result and stop
or, if all the solutions need to be found, continue by backtracking to the node‘s parent.
If s is not equal to d, we can terminate the node as non-promising if either of the following
two inequalities holds:
KNAPSACK PROBLEM
The knapsack problem, given n items of known weights w1, . . . , wn and values v1, . . . , vn and
a knapsack of weight capacity W, find the most valuable subset of the items that fits into the
knapsack.
4. Briefly explain NP-Hard and NP-Completeness with example. [M-14] [M-15] [N-15]
Class P: An algorithm solves a problem in polynomial time if its worst-case time efficiency
belongs to O(p(n)) where p(n) is a polynomial of the problem‘s input size n.
Problems that can be solved in polynomial time are called tractable, and problems that cannot be
solved in polynomial time are called intractable.
Class P is a class of decision problems that can be solved in polynomial time by
(deterministic) algorithms. This class of problems is called polynomial. (Class P)
Examples: Searching, Element uniqueness, primality test, graph acyclicity
Class NP: A nondeterministic algorithm is a two-stage procedure that takes as its input an
instance I of a decision problem and does the following.
Nondeterministic (―guessing‖) stage:
An arbitrary string S is generated that can be thought of as a candidate solution to the given instance I
(but may be complete gibberish as well).
· Class NP is the class of decision problems that can be solved by nondeterministic polynomial
algorithms. This class of problems is called nondeterministic polynomial.
· Examples: TSP, AP, Graph coloring problem, partition problem, Hamiltonian circuit problem
The n-queens problem is to place n queens on an n × n chessboard so that no two queens attack each
other by being in the same row or in the same column or on the same diagonal.