0% found this document useful (0 votes)
119 views15 pages

Daa

The document discusses algorithms, including what they are, different types of algorithms, analyzing algorithm efficiency, and recursive and non-recursive algorithms. It provides examples of algorithms for matrix multiplication and calculating factorials recursively. Key steps in analyzing recursive and non-recursive algorithms are outlined.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
119 views15 pages

Daa

The document discusses algorithms, including what they are, different types of algorithms, analyzing algorithm efficiency, and recursive and non-recursive algorithms. It provides examples of algorithms for matrix multiplication and calculating factorials recursively. Key steps in analyzing recursive and non-recursive algorithms are outlined.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Design Analysis and Algorithms

1. Why is the need of studying algorithms?


From a practical standpoint, a standard set of algorithms from different areas of computing must
be known, in addition to be able to design them and analyze their efficiencies. From a theoretical
standpoint the study of algorithms in the cornerstone of computer science.
2. What is algorithmics?
The study of algorithms is called algorithmic. It is more than a branch of computer science. It is
the core of computer science and is said to be relevant to most of science, business and technology.
3. What is an algorithm?
An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for
obtaining a required output for any legitimate input in finite amount of time.
4. Give the diagram representation of Notion of algorithm.

5. What is the formula used in Euclid’s algorithm for finding the greatest common divisor of two
numbers?
Euclid’s algorithm is based on repeatedly applying the equality
Gcd(m,n)=gcd(n,m mod n) until m mod n is equal to 0, since gcd(m,0)=m.
6. What are the three different algorithms used to find the gcd of two numbers?
The three algorithms used to find the gcd of two numbers are ._
 Euclid’s algorithm ._
 Consecutive integer checking algorithm ._
 Middle school procedure
7. What are the fundamental steps involved algorithmic problem solving?in
The fundamental steps are ._Understanding the problem
Ascertain the capabilities of computational device
Choose between exact and approximate problem solving .
Decide on appropriate data structures .
Algorithm design techniques .
Methods for specifying the algorithm .
Proving an algorithms correctness .
Analyzing an algorithm .
Coding an algorithm
8. What is an algorithm design technique?
An algorithm design technique is a general approach to solving problems algorithmically that is
applicable to a variety of problems from different areas of computing.
9. What is pseudocode?
A pseudocode is a mixture of a natural language and programming language constructs to
specify an algorithm. A pseudocode is more precise than a natural language and its usage often yields
more concise algorithm descriptions.
10. What are the types of algorithm efficiencies?
The two types of algorithm efficiencies are
 Time efficiency: indicates how fast the algorithm runs
 Space efficiency: indicates how much extra memory the algorithm
needs
11. Mention some of the important problem types?
Some of the important problem types are as follows
Sorting
 Searching
 String processing
 Graph problems
 Combinatorial problems
 Geometric problems
 Numerical problems
12. What are the classical geometric problems?
The two classic geometric problems are
 The closest pair problem: given n points in a plane find the closest pair
among them
 The convex hull problem: find the smallest convex polygon that would
include all the points of a given set.
13. What are the steps involved in the analysis framework?
The various steps are as follows
 Measuring the input’s size
 Units for measuring running time
 Orders of growth
 Worst case, best case and average case efficiencies
14. What is the basic operation of an algorithm and how is it identified?
The most important operation of the algorithm is called the basic operation of the
algorithm, the operation that contributes the most to the total running time.
It can be identified easily because it is usually the most time consuming
operation in the algorithms innermost loop.
15. What is the running time of a program implementing the algorithm?
The running time T(n) is given by the following formula
T(n) § copC(n)
cop is the time of execution of an algorithm’s basic operation on a particular
computer and C(n) is the number of times this operation needs to be
executed for the particular algorithm.
16. What are exponential growth functions?
The functions 2n and n! are exponential growth functions, because these two
functions grow so fast that their values become astronomically large even for
rather smaller values of n.
17. What is worst-case efficiency?
The worst-case efficiency of an algorithm is its efficiency for the worst-case input
of size n, which is an input or inputs of size n for which the algorithm runs the
longest among all possible inputs of that size.
18. What is best-case efficiency?
The best-case efficiency of an algorithm is its efficiency for the best-case input
of size n, which is an input or inputs for which the algorithm runs the fastest
among all possible inputs of that size.
19. What is average case efficiency?
The average case efficiency of an algorithm is its efficiency for an average case
input of size n. It provides information about an algorithm behavior on a “typical”
or “random” input.
20. What is amortized efficiency?
In some situations a single operation can be expensive, but the total time for the
entire sequence of n such operations is always significantly better that the worst
case efficiency of that single operation multiplied by n. this is called amortized
efficiency.
21. Define O-notation?
A function t(n) is said to be in O(g(n)), denoted by t(n) O(g(n)), if t(n) is
bounded above by some constant multiple of g(n) for all large n, i.e., if there exists
some positive constant c and some nonnegative integer n0 such that
T(n) ” cg(n) for all n • n0
22. Define -notation?
A function t(n) is said to be in (g(n)), denoted by t(n) (g(n)), if t(n) is
bounded below by some constant multiple of g(n) for all large n, i.e., if there exists
some positive constant c and some nonnegative integer n0 such that
T(n) • cg(n) for all n • n0
23. Define -notation?
A function t(n) is said to be in (g(n)), denoted by t(n) (g(n)), if t(n) is
bounded both above & below by some constant multiple of g(n) for all large n, i.e.,
if there exists some positive constants c1 & c2 and some nonnegative integer
n0 such that
c2g(n) ” t(n) ” c1g(n) for all n • n0
24. Mention the useful property, which can be applied to the asymptotic notations and its
use?
If t1(n) O(g1(n)) and t2(n) O(g2(n)) then t1(n)+t2(n) max {g1(n),g2(n)} this
property is also true for and notations. This property will be useful in
analyzing algorithms that comprise of two consecutive executable parts.
25. What are the basic asymptotic efficiency classes?
The various basic efficiency classes are
 Constant : 1
 Logarithmic : log n
 Linear : n
 N-log-n : nlog n
 Quadratic : n2
 Cubic :n 3
 Exponential : 2n
 Factorial : n!
26. Write the general plan for analyzing the efficiency for non-recursive algorithms.
The various steps include
 Decide on a parameter indicating input’s size.
 Identify the algorithms basic operation.
 Check whether the number of times the basic operation is executed
depends on size of input. If it depends on some additional property the
worst, average and best-case efficiencies have to be investigated
separately.
 Set up a sum expressing the number of times the algorithm’s basic
operation is executed.
 Using standard formulas and rules of manipulation, find a closed-form
formula for the count or at least establish its order of growth.
27. Mention the non-recursive algorithm for matrix multiplication?
ALGORITHM MatrixMultiplication(A[0..n-1,0..n-1], B[0..n-1,0..n-1])
//Multiplies two square matrices of order n by the definition based
//algorithm
//Input : Two n-by-n matrices A and B
//Output : Matrix C = AB
for I Å 0 to n-1 do
for j Å 0 to n-1 do
C[I,j] Å 0.0
for k Å 0 to n-1 do
C[I,j] Å C[I,j] + A[I,k]*B[k,j]
return C
28. Write a recursive algorithm to find the n-th factorial number.
ALGORITHM F(n)
// Computes n! recursively
// Input A non-negative integer n
// Output The value of n!
if n=0 return 1
else return F(n-1) * n
29. What is the recurrence relation to find out the number of multiplications and the initial
condition for finding the n-th factorial number?
The recurrence relation and initial condition for the number of multiplications
is
M(n)=M(n-1)+1 for n>0
M(0)=0
30. Write the general plan for analyzing the efficiency for recursive algorithms.
The various steps include
 Decide on a parameter indicating input’s size.
 Identify the algorithms basic operation.
 Check whether the number of times the basic operation is executed
depends on size of input. If it depends on some additional property the
worst, average and best-case efficiencies have to be investigated
separately.
 Set up a recurrence relation with the appropriate initial condition , for
the number of times the basic operation is executed.
 Solve the recurrence or at least ascertain the orders of growth of its
solution.
31. Write a recursive algorithm for solving Tower of Hanoi problem.
ALGORITHM
 To move n>1 disks from peg1 to peg3, with peg2 as auxiliary, first
move recursively n-1 disks from peg1 to peg2 with peg3 as auxiliary.

 Then move the largest disk directly from peg1 to peg3


 Finally move recursively n-1 disks from peg2 to peg3 with peg1 as
auxiliary
 If n=1 simply move the single disk from source peg to destination peg.
32. What is the basic operation in the Tower of Hanoi problem and give the
recurrence relation for the number of moves?
The moving of disks is considered the basic operation in the Tower of Hanoi
problem and the recurrence relation for the number of moves is given as
M(n)=2M(n)+1 for n>1
M(1)=1
33. What is the general plan for the Empirical Analysis of Algorithm Efficiency?
The general plan is as follows
 Understand the experiment’s purpose.
 Decide on the efficiency metric M to be measured & the measurement unit.
 Decide on characteristics of the input sample
 Prepare a program implementing the algorithm for the experimentation
 Generate a sample of inputs
 Run the algorithm on the sample input and record the data observed
 Analyze the data obtained
34. Define Brute force approach?
Brute force is a straightforward approach to solving a problem, usually directly
based on the problem’s statement and definitions of the concepts involved. The
brute force approach is one that is easiest to apply.
35. What are the advantages of brute force technique?
The various advantages of brute force technique are
 Brute force applicable to a very wide variety of problems. It is used for many
elementary but important algorithmic tasks

 For some important problems this approach yields reasonable


algorithms of at least some practical value with no limitation on
instance size
 The expense to design a more efficient algorithm may be unjustifiable
if only a few instances of problems need to be solved and a brute force
algorithm can solve those instances with acceptable speed
 Even if inefficient in general it can still be used for solving small-size
instances of a problem
 It can serve as a yardstick with which to judge more efficient
alternatives for solving a problem
36. What is selection sort?
Selection sort is started by scanning the entire list to find the smallest element and
exchange it with the first element, putting the first element in the final position
in the sorted list. Then the scan starts from the second element to find the
smallest among n-1 elements and exchange it with the second element.

A0 A1 ………… Ai-1 | Ai……..…,Amin,………,An-1


In their final position The last n-I elements

37. Mention the pseudocode for selection sort.


ALGORITHM SelectionSort(A[0..n-1])
//The algorithm sorts a given array by selection sort
//Input: An array A[0..n-1] of orderable elements
//Output: Array A[0..n-1] sorted in ascending order for I Å
0 to n-2 do
min Å I
for j Å I+1 to n-1 do
if A[j] < A[min] min Å j swap
A[I] and A[min]
38. What is bubble sort?
Another brute force approach to sort a problem is to compare adjacent
elements of the list and exchange them if they are out of order, so we end up
“bubbling up” the largest element to the last position in the list. The next pass
bubbles up the second largest element, and so on until n-1 passes , the list is sorted.
Pass I can be represented as follows
?
A0,……, Aj Aj+1,……, An-I-1 | An-I …… An-1
In their final positions
39. Give an algorithm for bubble sort?
ALGORITHM BubbleSort(A[0..n-1])
//The algorithm sorts array A[0..n-1] by bubble sort
//Input: An array A[0..n-1] of orderable elements

//Output: Arrar A[0..n-1] sorted in ascending order


for I Å 0 to n-2 do
for j Å 0 to n-2-I do
if A[j+1]<A[j] swap A[j] and A[j+1]
40. Give the benefit of application of brute force technique to solve a problem.
With the application of brute force strategy, the first version of an algorithm
obtained can often be improved with a modest amount of effort. So a first
application of the brute force approach often results in an algorithm that can be
improved with a modest amount of effort.
41. Explain about the enhanced version of sequential search.
Sequential search simply compares successive elements of a list with a given search
key until either a match is encountered or the list is exhausted without finding a
match. The enhancement in this version is to append the search key
to the end of the list , then the search for the key will have to be successful &
so we can eliminate a check for the list’s end on each iteration.
42. Give the algorithm for the enhanced version of sequential search.
ALGORITHM SequentialSearch2(A[0..n-1],K)
//The algorithm implements sequential search with the search key as
sentinael
//Input: An array A of n elements and a search key K
//Output: The position of the first element in a[0..n-1] whose value is equal to
K or //–1 if no such element is found
A[n] Å K I Å 0
while A[I] K do
I Å I+1
If I < n return I
else return -1
43. What is the improvement that can be applied to sequential search if the list is sorted?
The straightforward improvement that can be incorporated in sequential search
if a given list is known to be sorted is that searching in the list can be stopped as
soon as an element greater than or equal to the search key is encountered.
44. Give the general plan for divide-and-conquer algorithms.
The general plan is as follows
™ A problems instance is divided into several smaller instances of the same
problem, ideally about the same size
™ The smaller instances are solved, typically recursively
™ If necessary the solutions obtained are combined to get the solution of the
original problem
45. State the Master theorem and its use.
If f(n) (nd) where d 0 in recurrence equation T(n) = aT(n/b)+f(n), then

(ndd) if
(n log if
T(n)
n)(nlog
a) a<bdd d
b a=b
if a>b

The efficiency analysis of many divide-and-conquer algorithms are greatly


simplified by the use of Master theorem.
46. What is the general divide-and-conquer recurrence relation?
An instance of size ‘n’ can be divided into several instances of size n/b, with
‘a’ of them needing to be solved. Assuming that size ‘n’ is a power of ‘b’, to
simplify the analysis, the following recurrence for the running time is
obtained:
T(n) = aT(n/b)+f(n)
Where f(n) is a function that accounts for the time spent on dividing the
problem into smaller ones and on combining their solutions.
47. Define mergesort.
Mergesort sorts a given array A[0..n-1] by dividing it into two halves a[0..(n/2)-
1] and A[n/2..n-1] sorting each of them recursively and then merging the two smaller
sorted arrays into a single sorted one.
48. Give the algorithm for mergesort.
ALGORITHM Mergesort(A[0..n-1])
//Sorts an array A[0..n-1] by recursive mergesort
//Input: An array A[0..n-1] of orderable elements
//Output: Array A[0..n-1] sorted in nondecreasing order
if n > 1
copy A[0..(n/2)-1] to B[0..(n/2)-1] copy
A[(n/2)..n-1] to C[0..(n/2)-1]
Mergesort(B[0..(n/2)-1])

Mergesort(C[0..(n/2)-1])
Merge(B,C,A)
49. What is the difference between quicksort and mergesort?
Both quicksort and mergesort use the divide-and-conquer technique in which the
given array is partitioned into subarrays and solved. The difference lies in the
technique that the arrays are partitioned. For mergesort the arrays are partitioned
according to their position and in quicksort they are partitioned according to the
element values.
50. Give the algorithm for Quicksort.
ALGORITHM Quicksort(A[l..r])
//Sorts a array by quicksort
//Input: A subarray A[l..r] of A[0..n-1], defined by the left and right indices l & r
//Output: the subarray A[l..r] sorted in nondecreasing order
if l < r
s Å Partition(A[l..r])
Quicksort(A[l..s-1])
Quicksort(A[s+1..r])
51. What is binary search?
Binary search is a remarkably efficient algorithm for searching in a sorted array. It
works by comparing a search key K with the arrays middle element A[m]. if they
match the algorithm stops; otherwise the same operation is repeated recursively for
the first half of the array if K < A[m] and the second half if K > A[m].
K

A[0]………A[m-1] A[m] A[m+1]………A[n-1]


search here if K<A[m] search here if K>A[m]

UNIT – II
1. What is greedy technique?
Greedy technique suggests a greedy grab of the best alternative available in the
hope that a sequence of locally optimal choices will yield a globally optimal solution
to the entire problem. The choice must be made as follows
™ Feasible : It has to satisfy the problem’s constraints
™ Locally optimal : It has to be the best local choice among all feasible choices
available on that step.
™ Irrevocable : Once made, it cannot be changed on a subsequent step
of the algorithm
2.Mention the algorithm for Prim’s algorithm.
ALGORITHM Prim(G)
//Prim’s algorithm for constructing a minimum spanning tree
//Input A weighted connected graph G= V , E
//Output ET, the set of edges composing a minimum spanning tree of G VT Å
{v0}
ET Å
for i Å 1 to |V|-1 do
Find the minimum-weight edge e*=(v*,u*) among all the edges (v,u)
such that v is in VT and u is in V-VT
V T Å VT {u*}
ET Å E T {e*}
return ET
3.What are the labels in Prim’s algorithm used for?
Prim’s algorithm makes it necessary to provide each vertex not in the current tree with the
information about the shortest edge connecting the vertex to a tree vertex. The information
is provided by attaching two labels toa vertex
™ The name of the nearest tree vertex
™ The length of the corresponding edge
4.How are the vertices not in the tree split into?
The vertices that are not in the tree are split into two sets
™ Fringe : It contains the vertices that are not in the tree but are adjacent
to atleast one tree vertex.
™ Unseen : All other vertices of the graph are called unseen because they are
yet to be affected by the algorithm.
5.What are the operations to be done after identifying a vertex u* to be added to the
tree?
After identifying a vertex u* to be added to the tree, the following two operations need to be
performed
™ Move u* from the set V-VT to the set of tree vertices VT.
™ For each remaining vertex u in V-VT that is connected to u* by a shorter
edge than the u’s current distance label, update its labels by u* and the weight of the edge
between u* and u, respectively.
6.What is a min-heap?
A min-heap is a mirror image of the heap structure. It is a complete binary
tree in which every element is less than or equal to its children. So the root of the
min-heap contains the smallest element.
7.What is the use of Kruskal’s algorithm and who discovered it?
Kruskal’s algorithm is one of the greedy techniques to solve the
minimum spanning tree problem. It was discovered by Joseph Kruskal when he
was a second-year graduate student.
8.Give the Kruskal’s algorithm.
ALGORITHM Kruskal(G)
//Kruskal’s algorithm for constructing a minimum spanning tree
//Input A weighted connected graph G= V , E
//Output ET, the set of edges composing a minimum spanning tree of G
sort E in non decreasing order of the edge weights w(ei1) ……… w(ei|E|)
ET Å
Ecounter Å 0
kÅ0
while ecounter < |V|-1
k Å k+1
if ET {eik} is acyclic
ET Å ET {eik}; ecounter Å ecounter + 1
return ET
9.What is a subset’s representative?
One element from each of the disjoint subsets in a collection is used as the
subset’s representative. Some implementations do not impose any specific
constraints on such a representative, others do so by requiring the smallest
element of each subset to be used as the subset’s representative.
10.What is the use of Dijksra’s algorithm?
Dijkstra’s algorithm is used to solve the single-source shortest-paths
problem: for a given vertex called the source in a weighted connected graph, find
the shortest path to all its other vertices. The single-source shortest-paths problem
asks for a family of paths, each leading from the source to a different vertex in the
graph, though some paths may have edges in common.
11.What is encoding and mention its types?
Encoding is the process in which a text of ‘n’ characters from some
alphabet is assigned with some sequence of bits called codewords. There are two
types of encoding they are
™ Fixed-length encoding
™ Variable-length encoding
12.What is the problem faced by variable-length encoding and how can it be avoided?
Variable-length encoding which assigns codewords of different lengths to different characters
introduces a problem of identifying how many bits of an encoded text represent the first
character or generally the ith character. To avoid this prefix-free codes or prefix codes
are used. In prefix codes, no codeword is a prefix of a codeword of another character.
13. Mention the Huffman’s algorithm.
ALGOITHM Huffman
 Initialize n one-node trees and label them with the characters of the
alphabet. Record the frequency of each character in its tree’s root to
indicate the tree’s weight.
 Repeat the following operation until a single tree is obtained. Find two trees
with the smallest weight. Make them the left and right subtree of
a new tree and record the sum of their weights in the root of the new tree
as its weight.
A tree constructed by the above algorithm is called Huffman tree and it defines
the Huffman code
14.What is minimum cost spanning tree?
 A spanning tree of a graph is an undirected tree consisting of only those edges that are
necessary to connect all the vertices in the original graph.
 A Spanning tree has a property that for any pair of vertices there exist only one path
between them and the insertion of an edge to a spanning tree form a unique cycle.
15. What is feasible solution?
 A problem with N inputs will have some constraints. Any subsets that satisfy these
constraints are called a feasible solution.
16. What is optimal solution?
 A feasible solution that either maximize or minimize a given objectives function is
called an optimal solution.
17. What are the application of the spanning tree?
1. Analysis of electrical circuits.
2. Shortest route problems
18. What is minimization problem?
 A feasible solution that minimize a given objectives function is called minimization
problem.
19.What is maximization Problem?
 A feasible solution that maximize a given objectives function is called an
maximization Problem.

UNIT- III
1.What is dynamic programming and who discovered it?
Dynamic programming is a technique for solving problems with
overlapping subproblems. These subproblems arise from a recurrence
relating a solution to a given problem with solutions to its smaller
subproblems only once and recording the results in a table from which the
solution to the original problem is obtained. It was invented by a prominent U.S
Mathematician, Richard Bellman in the 1950s.
2.Define transitive closure.
The transitive closure of a directed graph with ‘n’ vertices is defined as the n-
by-n Boolean matrix T={tij}, in which the elements in the ith row (1 i n) and the
jth column (1 j n) is 1 if there exists a non trivial directed path from the ith
vertex to the jth vertex otherwise, tij is 0
3.What is the formula used by Warshall’s algorithm?
The formula for generating the elements of matrix R(k) from the matrix R(k-1) is
rij(k) = rij(k-1) or rik(k-1) and
j rk (k-1)
This formula implies the following rule for generating elements of matrix R(k)
from the elements of matrix R(k-1)
If an element rij is 1 in R(k-1), it remains 1 in R(k)
If an element rij is 0 in R(k-1), it has to be changed to 1 in R(k) if and only
if the element in its row ‘i’ and column ‘k’ and the element in its row ‘k’
and column ‘j’ are both 1’s in R(k-1)
4.Give the Warshall’s algorithm.
ALGORITHM Warshall(A[1..n,1..n])
//Implements Warshall’s algorithm for computing the transitive closure
//Input The adjacency matrix A of a digraph with ‘n’ vertices
//Output The transitive closure of the digraph
R(0) Å A
for k Å 1 to n do
for i Å 1 to n do
for j Å 1 to n do
R(k)[I,j] Å R(k-1)[I,j] or R(k-1)[I,k] and R(k-1)[k,j]
return R (n)
5.Give the Floyd’s algorithm
ALGORITHM Floyd(W[1..n,1..n])
//Implements Floyd’s algorithm for the all-pair shortest–path problem
//Input The weight matrix W of a graph
//Output The distance matrix of the shortest paths’ lengths
DÅW
for k Å 1 to n do
for i Å 1 to n do
for j Å 1 to n do
D[I,j] Å min{D[I,j], D[I,k] + D[k,j]}
return D

6.How many binary search trees can be formed with ‘n’ keys?
The total number of binary search trees with ‘n’ keys is equal to the nth
Catalan number
2n 1
c(n) = for n >0, c(0) = 1,
n n
1
which grows to infinity as
fast as 4n/n1.5.
7.Give the algorithm used to find the optimal binary search tree.
ALGORITHM OptimalBST(P[1..n])
//Finds an optimal binary search tree by dynamic programming
//Input An array P[1..n] of search probabilities for a sorted list of ‘n’ keys
//Output Average number of comparisons in successful searches in the
optimal //BST and table R of subtrees’ roots in the optimal BST
for I Å 1 to n do
C[I,I-1] Å 0
C[I,I] Å P[I]
R[I,I] Å I
C[n+1,n] Å 0
for d Å 1 to n-1 do
for i Å 1 to n-d do j
Å i +d
minval Å
for k Å I to j do
if C[I,k-1]+C[k+1,j] < minval
minval Å C[I,k-1]+C[k+1,j]; kmin Å k
R[I,j] Å k
Sum ÅP[I]; for s Å I+1 to j do sum Å sum + P[s]
C[I,j] Å minval+sum
Return C[1,n], R
UNIT - IV
1.What is backtracking?
Backtracking constructs solutions one component at a time and such
partially constructed solutions are evaluated as follows
If a partially constructed solution can be developed further without
violating the problem’s constraints, it is done by taking the
first remaining legitimate option for the next component.
If there is no legitimate option for the next component, no alternatives
for the remaining component need to be considered. In this case, the
algorithm backtracks to replace the last component of the partially
constructed solution with its next option.
2.What is a 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 a 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 of the solution, the nodes in
the second level represent the choices for the second component and so on.
3.What is a promising node in the state-space tree?
A node in a state-space tree is said to be promising if it corresponds to a partially
constructed solution that may still lead to a complete solution.
4.What is a non-promising node in the state-space tree?
A node in a state-space tree is said to be promising if it corresponds to a partially
constructed solution that may still lead to a complete solution;otherwise it is called non-
promising.
5.What do leaves in the state space tree represent?
Leaves in the state-space tree represent either non-promising dead ends or complete
solutions found by the algorithm.
6,What is the manner in which the state-space tree for a backtracking algorithm is
constructed?
In the majority of cases, a state-space tree for backtracking algorithm is constructed in
the manner of depth-first search. If the current node is promising, its child is
generated by adding the first remaining legitimate option for the next component of a
solution, and the processing moves to this child.
If the current node turns out to be non-promising, the algorithm backtracks to the node’s
parent to consider the next possible solution to the problem, it either stops or
backtracks to continue searching for other possible solutions.
7.What is n-queens problem?
The problem is to place ‘n’ queens on an n-by-n chessboard so that no two queens attack
each other by being in the same row or in the column or in the same diagonal.
8.Draw the solution for the 4-queen problem.

Q Q
Q Q
Q Q
Q Q

9.Define the Hamiltonian circuit.


The Hamiltonian is defined as a cycle that passes through all the vertices of the
graph exactly once. It is named after the Irish mathematician Sir William Rowan
Hamilton (1805-1865).It is a sequence of n+1 adjacent vertices
vi0, vi1,……, vin-1, vi0
where the first vertex of the sequence is same as the last one while all the other n-1
vertices are distinct.
10.What is the 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’.
11.When can a node be terminated in the subset-sum problem?
The sum of the numbers included are added and given as the value for the root as s’.
The node can be terminated as a non-promising node if either of the two equalities
holds:
s’+si+1>d (the sum s’ is too large)
n
s’+ sj<d (the sum s’ is too small)
j i 1
12.How can the output of a backtracking algorithm be thought of?
The output of a backtracking algorithm can be thought of as an n-tuple (x1, …xn) where
each coordinate xi is an element of some finite linearly ordered set Si. If such a
tuple (x1, …xi) is not a solution, the algorithm finds the next element in Si+1 that is
consistent with the values of (x1, …xi) and the problem’s constraints and adds it to
the tuple as its (I+1)st coordinate. If such an element does not exist, the algorithm
backtracks to consider the next value of xi, and so on.
13.Give a template for a generic backtracking algorithm.
ALGORITHM Backtrack(X[1..i])
//Gives a template of a generic backtracking algorithm
//Input X[1..i] specifies the first I promising components of a solution
//Output All the tuples representing the problem’s solution
if X[1..i] is a solution write X[1..i]
else
for each element x Si+1 consistent with X[1..i] and the constraints do
X[i+1] Å x
Backtrack(X[1..i+1])
14. What are the tricks used to reduce the size of the state-space tree?
The various tricks are
 Exploit the symmetry often present in combinatorial problems. So some
solutions can be obtained by the reflection of others. This cuts the size of the tree
by about half.
 Preassign values to one or more components of a solution
 Rearranging the data of a given instance.

15.What is the method used to find the solution in n-queen problem by symmetry?
The board of the n-queens problem has several symmetries so that some solutions
can be obtained by other reflections. Placements in the last n/2 columns need not
be considered, because any solution with the first queen in square (1,i), n/2 i n
can be obtained by reflection from a solution with the first queen in square (1,n-i+1)

16.What are the additional features required in branch-and-bound when compared


to backtracking?
Compared to backtracking, branch-and-bound requires:
™ A way to provide, for every node of a state space tree, a bound on the
best value of the objective function on any solution that can be
obtained by adding further components to the partial solution
represented by the node.
™ The value of the best solution seen so far
17.What is a feasible solution 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.

UNIT – V
1.When can a search path be terminated in a branch-and-bound algorithm?
A search path at the current node in a state-space tree of a branch-and-bound
algorithm can be terminated if
™ The value of the node’s bound is not better than the value of the best solution seen
so far
™ The node represents no feasible solution because the constraints of the problem
are already violated.
™ The subset of feasible solutions represented by the node consists of a single point
in this case compare the value of the objective function for this feasible solution
with that of the best solution seen so far and update the latter with the former
if the new solution is better.
2.What is the assignment problem?
Assigning ‘n’ people to ‘n’ jobs so that the total cost of the assignment is as small as
possible. The instance of the problem is specified as a n-by-n cost matrix C so that
the problem can be stated as: select one element in each row of the matrix so that
no two selected items are in the same column and the sum is the smallest possible.
3.What is best-first branch-and-bound?
It is sensible to consider a node with the best bound as the most promising,
although this does not preclude the possibility that an optimal solution will
ultimately belong to a different branch of the state-space tree. This strategy is
called best-first branch-and-bound.
5.What is knapsack problem?
Given n items of known weights wi and values vi, i=1,2,…,n, and a knapsack of
capacity W, find the most valuable subset of the items that fit the knapsack. It is
convenient to order the items of a given instance in descending order by their
value-to-weight ratios. Then the first item gives the best payoff per weight unit and
the last one gives the worst payoff per weight unit.
6.Give the formula used to find the upper bound for knapsack problem.
A simple way to find the upper bound ‘ub’ is to add ‘v’, the total value of the items
already selected, the product of the remaining capacity of the knapsack W-w and
the best per unit payoff among the remaining items, which
is vi+1/wi+1
ub = v + (W-w)( vi+1/wi+1)
7.What is the traveling salesman problem?
The problem can be modeled as a weighted graph, with the graph’s vertices
representing the cities and the edge weights specifying the distances. Then the
problem can be stated as finding the shortest Hamiltonian circuit of the graph,
where the Hamiltonian is defined as a cycle that passes through all the vertices of
the graph exactly once.
8.What are the strengths of backtracking and branch-and-bound?
The strengths are as follows
™ It is typically applied to difficult combinatorial problems for which no
efficient algorithm for finding exact solution possibly exist
™ It holds hope for solving some instances of nontrivial sizes in an
acceptable amount of time
™ Even if it does not eliminate any elements of a problem’s state space and
ends up generating all its elements, it provides a specific technique for
doing so, which can be of some value.

You might also like