I PART-A - vi institute of technology

advertisement
Vi Institute of Technology
Department of Computer Science
Question Bank
Unit- I
PART-A
1. What is performance measurement?
Performance measurement is concerned with obtaining the space and the time requirements of a
particular algorithm.
2. What is an algorithm?
An algorithm is a finite set of instructions that, if followed, accomplishes a particular task.
3. What are the characteristics of an algorithm?
1) Input
2) Output
3) Definiteness
4) Finiteness
5) Effectiveness
4. Define Program.
A program is the expression of an algorithm in a programming language. Sometimes works such
as procedure, function and subroutine are used synonymously program.
5. Write the For LOOP general format.
The general form of a for Loop is
For variable : = value 1 to value 2 step
Step do
{
<statement 1>
<statement n >
}
6. What is recursive algorithm?
An algorithm is said to be recursive if the same algorithm is invoked in the body. An algorithm
that calls itself is Direct recursive. Algorithm A is said to be indeed recursive if it calls another
algorithm, which in turn calls A.
7. What is space complexity?
The space complexity of an algorithm is the amount of memory it needs to run to completion.
8. What is time complexity?
The time complexity of an algorithm is the amount of computer time it needs to run to
completion.
9. Give the two major phases of performance evaluation
Performance evaluation can be loosely divided into two major phases:
(i) a prior estimates (performance analysis)
(ii) a Posterior testing(performance measurement)
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
10. Define input size.
The input size of any instance of a problem is defined to be the number of words (or the number
of elements) needed to describe that instance.
11. Define best-case step count.
The best-case step count is the minimum number of steps that can be executed for the given
parameters.
12. Define worst-case step count.
The worst-case step count is the maximum number of steps that can be executed for the given
parameters.
13. Define average step count.
The average step count is the average number of steps executed an instance with the given
parameters.
14. Define the asymptotic notation “Big on” (0)
The function f(n) = O(g(n)) iff there exist positive constants C and no such that f(n)£ C * g(n) for
all n, n ³n0.
15. Define the asymptotic notation “Omega” ( W ).
The function f(n) =W (g(n)) iff there exist positive constant C and no such that f(n) C * g(n) for
all n, n ³ n0.
16. Define the asymptotic t\notation “theta” (q )
The function f(n) =q (g(n)) iff there exist positive constant C1, C2, and no such that C1 g(n)£
f(n) £ C2 g(n) for all n, n ³ n0.
17. Define Little “oh”.
The function f(n) = 0(g(n))
If Lim f(n) = 0
n - μ g(n)
18. Define Little Omega.
The function f(n) = w (g(n))
if
Lim f(n) = 0
n - μ g(n)
19. Write algorithm using iterative function to fine sum of n numbers.
Algorithm sum(a,n)
{
S : = 0.0
For i=1 to n do
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
S : - S + a[i];
Return S;
}
20. Write an algorithm using Recursive function to fine sum of n numbers.
Algorithm Rsum (a,n)
{
If(n_ 0) then
Return 0.0;
Else Return Rsum(a, n- 1) + a(n);
}
21. What are the basic asymptotic efficiency classes?
The various basic efficiency classes are
Constant:1
Logarithmic: log n
Page 4
Linear: n
N-log-n: n log n
Quadratic: n2
Cubic: n3
Exponential:2n
Factorial:n!
22. Define Time Space Tradeoff.
Time and space complexity can be reduced only to certain levels, as later on reduction of time
increases the space and vice-versa. This is known as Time-space trade-off.
23. Why do we need algorithm analysis?
• Writing a working program is not good enough.
• The program may be in-efficient
• If the program is run on a large data set, then the running time becomes an issue.
24. List the factors which affects the running time of the algorithm.
A. Computer
B. Compiler
C. Algorithm used
D. Input to the algorithm
i. The content of the input affects the running time
ii. Typically, the input size is the main consideration.
25. What is recurrence equation?
A recurrence equation is an equation or inequality that describes a function in terms of its value
on smaller inputs.
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
26. What is classification of the recurrence equation?
Recurrence Equations can be classified into
1. Homogeneous
2. Inhomogeneous
27. What is the need of studying algorithms?
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.
28. What is algorithmics?
The study of algorithms is called algorithmics. 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.
29. 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.
30. 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
31. 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.
32. 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.
33. 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
34. 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.
35. What are exponential growth functions?
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
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.
36. 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.
37. 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.
38. 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.
39. 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.
40. 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.
41. 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
42. 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
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
43. What are the fundamental steps involved in algorithmic problem solving?
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
UNIT II
1. Define the divide and conquer method.
Given a function to compute on ‘n’ inputs the divide-and-conquer strategy suggests splitting the
inputs in to ’k’ distinct subsets, 1<k <n, yielding ‘k’ subproblems. The subproblems must be
solved, and then a method must be found to combine subsolutions into a solution of the whole. If
the subproblems are still relatively large, then the divide-and conquer strategy can possibly be
reapplied.
2. Define control abstraction.
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
A control abstraction we mean a procedure whose flow of control is clear but whose primary
operations are by other procedures whose precise meanings are left undefined.
3. Write the Control abstraction for Divide-and conquer.
Algorithm D And(r)
{
if small(p) then return S(r);
else
{
divide P into smaller instance _ 1, _ 2, _ k, k ³ 1;
Apply D and C to each of these subproblems
Return combine (DAnd C(_1) DAnd C(_2),----, DAnd ((_k));
}
}
4. What is the substitution method?
One of the methods for solving any such recurrence relation is called the substitution method.
5. What is the binary search?
If ‘q’ is always chosen such that ‘aq’ is the middle element(that is, q=[(n+1)/2), then the
resulting search algorithm is known as binary search.
6. Give computing time for Bianry search?
The computing time of binary search by giving formulas that describe the best, average and
worst cases. Successful searches q(1) q(logn) q(Logn) best average worst unsuccessful searches
q(logn) best, average, worst.
7. Define external path length?
The external path length E, is defines analogously as sum of the distance of all external nodes
from the root.
8. Define internal path length.
The internal path length ‘I’ is the sum of the distances of all internal nodes from the root.
9. What is the maximum and minimum problem?
The problem is to find the maximum and minimum items in a set of ‘n’ elements. Though this
problem may look so simple as to be contrived, it allows us to demonstrate divide and conquer in
simple setting.
10. What is the Quick sort?
n quicksort, the division into subarrays is made so that the sorted sub arrays do not need to be
merged later.
11. Write the Anlysis for the Quick sot.
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
In analyzing QUICKSORT, we can only make the number of element comparisons c(n). It is
easy to see that the frequency count of other operations is of the same order as C(n).
12. Is insertion sort better than the merge sort?
Insertion sort works exceedingly fast on arrays of less then 16 elements, though for large ‘n’ its
computing time is O(n2).
13. Write a algorithm for straightforward maximum and minimum>
algorithm straight MaxMin(a,n,max,min)
//set max to the maximum and min to the minimum of a[1:n]
{
max := min: = a[i];
for i = 2 to n do
{
if(a[i] >max) then max: = a[i];
if(a[i] >min) then min: = a[i];
}
}
14. Give the recurrence relation of divide-and-conquer?
The recurrence relation is
T(n) = g(n)
T(n1) + T(n2) + ----+ T(nk) + f(n)
15. Write the algorithm for Iterative binary search?
Algorithm BinSearch(a,n,x)
//Given an array a[1:n] of elements in nondecreasing
// order, n>0, determine whether x is present
{
low : = 1;
high : = n;
while (low < high) do
{
mid : = [(low+high)/2];
if(x < a[mid]) then high:= mid-1;
else if (x >a[mid]) then low:=mid + 1;
else return mid;
}
return 0;
}
16. What are internal nodes?
The circular node is called the internal nodes.
17. Describe the recurrence relation for merge sort?
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
If the time for the merging operation is proportional to n, then the computing time of merge sort
is described by the recurrence relation n = 1, a constant T(n) = a
2T (n/2) + n n >1, a constant
18. What is meant by feasible solution?
Given n inputs and we are required to form a subset such that it satisfies some given constraints
then such a subset is called feasible solution.
19. Write any two characteristics of Greedy Algorithm?
To solve a problem in an optimal way construct the solution from given set of candidates.
As the algorithm proceeds, two other sets get accumulated among this one set contains the
candidates that have been already considered and chosen while the other set contains the
candidates that have been considered but rejected.
20. Define optimal solution?
A feasible solution either maximizes or minimizes the given objective function is called as
optimal solution.
21. What is Knapsack problem?
A bag or sack is given capacity n and n objects are given. Each object has weight wi and profit pi
.Fraction of object is considered as xi (i.e) 0<=xi<=1 .If fraction is 1 then entire object is put into
sack. When we place this fraction into the sack we get wixi and pixi.
22. Define weighted tree.
A directed binary tree for which each edge is labeled with a real number (weight) is called as
weighted tree.
23. What is the use of TVSP?
In places where the loss exceeds the tolerance level boosters have to the placed. Given a network
and loss tolerance level the tree vertex splitting problems is to determine an optimal placement of
boosters.
24. What is the Greedy choice property?
• The first component is greedy choice property (i.e.) a globally optimal solution can arrive at by
making a locally optimal choice.
• The choice made by greedy algorithm depends on choices made so far but it cannot depend on
any future choices or on solution to the sub problem. • It progresses in top down fashion.
25. What is greedy method?
Greedy method is the most important design technique, which makes a choice that looks best at
that moment. A given ‘n’ inputs are required us to obtain a subset that satisfies some constraints
that is the feasible solution. A greedy method suggests that one can device an algorithm that
works in stages considering one input at a time.
26. What are the steps required to develop a greedy algorithm?
• Determine the optimal substructure of the problem.
• Develop a recursive solution.
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
• Prove that at any stage of recursion one of the optimal choices is greedy choice. Thus it is
always safe to make greedy choice.
• Show that all but one of the sub problems induced by having made the greedy choice are
empty.
• Develop a recursive algorithm and convert into iterative algorithm.
27. What is activity selection problem?
The ‘n’ task will be given with starting time si and finishing time fi. Feasible Solution is that the
task should not overlap and optimal solution is that the task should be completed in minimum
number of machine set.
28. Write the specification of TVSP
Let T= (V, E, W) be a weighted directed binary tree where
V_ vertex set
E_ edge set
W_ weight function for the edge.
W is more commonly denoted as w (i,j) which is the weight of the edge <i,j> _E.
29. Define forest.
Collection of sub trees that are obtained when root node is eliminated is known as forest
30. What does Job sequencing with deadlines mean?
• Given a set of ‘n’ jobs each job ‘i’ has a deadline di such that di>=0 and a
• Profit pi such that pi>=0.
• For job ‘i’ profit pi is earned iff it is completed within deadline.
• Processing the job on the machine is for 1unit of time. Only one machine is available.
31. Define post order traversal.
The order in which the TVSP visits the nodes of the tree is called the post order traversal.
32. Write the formula to calculate delay and also write the condition in which the node gets
splitted?
To calculate delay
d(u)=max{d(v)+w(u, v)}
v _ c(u)
The condition in which the node gets splitted are:
d(u)+w(u ,v)>_ and also d(u) is set to zero.
33. What is meant by tolerance level?
The network can tolerate the losses only up to a certain limit tolerance limit.
34. When is a task said to be late in a schedule?
A task is said to be late in any schedule if it finishes after its deadline else a task is early in a
schedule.
35. Define feasible solution for TVSP.
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
Given a weighted tree T(V,E,W) and a tolerance limit _ any subset X of V is a feasible solution
if d(T/X).
36. Define optimal solution for TVSP.
An optimal solution is one in which the number of nodes in X is minimized.
37. Write the general algorithm for Greedy method control abstraction.
Algorithm Greedy (a, n)
{
solution=0;
for i=1 to n do
{
x= select(a);
if feasible(solution ,x) then
solution=Union(solution ,x);
}
return solution;
}
38. Define optimal solution for Job sequencing with deadlines.
Feasible solution with maximum profit is optimal solution for Job sequencing with deadlines.
39. Give an non-recursive algorithm to find out the largest element in a list of n numbers.
ALGORITHM MaxElement(A[0..n-1]) //Determines the value of the largest element in a given
array //Input:An array A[0..n-1] of real numbers //Output: The value of the largest element in A
maxval  a[0] for I  1 to n-1 do if A[I] > maxval maxval  A[I] return maxval
39.What are the two basic rules for sum manipulation?
The two basic rules for sum manipulation are
cai = c ai
(ai  bi) = ai bi
40. Mention the two summation formulas?
The two summation formulas are
1 = u-l+1 where l u are some lower and upper integer limits = = 1+2+3+...+n = n(n+1)/2 n2/2
(n2)
41. 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.
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
Set up a sum expressing the number of times the algorithm 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.
42. Give a non-recursive algorithm for element uniqueness problem.
ALGORITHM UniqueElements(A[0..n-1])
//Checks whether all the elements in a given array are distinct
//Input :An array A[0..n-1]
//Output Returns 'true' if all elements in A are distinct and 'false' //otherwise
for I  to n-2 do
for j  I+1 to n-1 do
if A[I] = A[j] return false
return true
43. 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
44. 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
45. 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.
46. 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
47. What is the explicit formula for the nth Fibonacci number?
The formula for the nth Fibonacci number is given by
F(n)= 1/ ( n - n)
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
Where
=(1+ )/2
=(1- )/2
48. Write a recursive algorithm for computing the nth fibonacci number?
ALGORITHM F(n)
// Computes the nth Fibonacci number recursively by using the definition
// Input A non-negative integer n
// Output The nth Fibonacci number
if n 1 return n
else return F(n-1)+F(n-2)
49. Give the various system commands used for timing the program implementing the
algorithm.
The system commands are as follows
UNIX time command
C & C++ function clock
Java method currentTimeMillis() in the System class
50. What is algorithm visualization?
Algorithm visualization is a way to study algorithms. It is defined as the use of images to
convey some useful information about algorithms. That information can be a visual illustration
of algorithm's operation, of its performance on different kinds of inputs, or of its execution speed
versus that of other algorithms for the same problem.
51. What are the two variations of algorithm visualization?
The two principal variations of algorithm visualization"
Static algorithm visualization: It shows the algorithm's progress through a series of still images
Dynamic algorithm visualization: Algorithm animation shows a continuous movie like
presentation of algorithms operations
52. What are the guidelines in choosing the values of m, seed, a, b for linear congruential
method
The recommendations are as follows
seed May be chosen arbitrarily and is often set to current date and time
m Should be large and may be conveniently taken as 2w where w is the computer's word size
a Should be selected as an integer between 0.01m and 099m with no particular pattern in its
digits but such that a mod 8=5
b The value can be chosen as 1
53. What are the features that are desired in algorithm animation?
Peter Gloor, who was the principal developer of Animated Algorithms suggested the following
desirable features
Be consistent
Be interactive
Be clear and concise
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
Be forgiving to the user
Adapt to the knowledge level of the user
Emphasize the visual component
Keep the user interested
Incorporate both symbolic and iconic representations
Include algorithm's analysis & comparisons with other algorithms for the same problem
Include execution history
54. What are the applications of algorithm visualization?
The two applications are
Research: Based on expectations that algorithm visualization may help uncover some unknown
feature of the algorithm
Education: Seeks to help students learning algorithms
UNIT III
Dynamic Programming
1. Define dynamic programming.
Dynamic programming is an algorithm design method that can be used when a solution to the
problem is viewed as the result of sequence of decisions.
2. What are the features of dynamic programming?
• Optimal solutions to sub problems are retained so as to avoid recomputing their values.
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
• Decision sequences containing subsequences that are sub optimal are not considered.
• It definitely gives the optimal solution always.
3. What are the drawbacks of dynamic programming?
• Time and space requirements are high, since storage is needed for all level.
• Optimality should be checked at all levels.
4. Write the general procedure of dynamic programming.
The development of dynamic programming algorithm can be broken into a
sequence of 4 steps.
1. Characterize the structure of an optimal solution.
2. Recursively define the value of the optimal solution.
3. Compute the value of an optimal solution in the bottom-up fashion.
4. Construct an optimal solution from the computed information.
5. Define principle of optimality.
It states that an optimal sequence of decisions has the property that whenever the initial stage or
decisions must constitute an optimal sequence with regard to stage resulting from the first
decision.
6. Give an example of dynamic programming and explain.
An example of dynamic programming is knapsack problem. The solution to the knapsack
problem can be viewed as a result of sequence of decisions. We have to decide the value of xi for
1<i<n. First we make a decision on x1 and then on x2 and so on. An optimal sequence of
decisions maximizes the object function Spi xi.
7. Write about optimal merge pattern problem.
Two files x1 and x2 containing m & n records could be merged together to obtain one merged
file. When more than 2 files are to be merged together. The merge can be accomplished by
repeatedly merging the files in pairs. An optimal merge pattern tells which pair of files should be
merged at each step. An optimal sequence is a least cost sequence.
8. Explain any one method of finding the shortest path.
One way of finding a shortest path from vertex i to j in a directed graph G is to decide which
vertex should be the second, which is the third, which is the fourth, and so on, until vertex j is
reached. An optimal sequence of decisions is one that results in a path of least length.
9. Define 0/1 knapsack problem.
The solution to the knapsack problem can be viewed as a result of sequence of decisions. We
have to decide the value of xi. xi is restricted to have the value 0 or 1 and by using the function
knap(l, j, y) we can represent the problem as maximum Spi xi subject to Swi xi < y where l iteration, j - number of objects, y – capacity.
10. What is the formula to calculate optimal solution in 0/1 knapsack problem?
The formula to calculate optimal solution is
g0(m)=max{g1, g1(m-w1)+p1}.
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
11. Write about traveling salesperson problem.
Let g = (V, E) be a directed. The tour of G is a directed simple cycle that includes every vertex in
V. The cost of a tour is the sum of the cost of the edges on the tour. The traveling salesperson
problem to find a tour of minimum cost.
12. Write some applications of traveling salesperson problem.
• Routing a postal van to pick up mail from boxes located at n different sites.
• Using a robot arm to tighten the nuts on some piece of machinery on an assembly line.
• Production environment in which several commodities are manufactured on the same set of
machines.
13. Give the time complexity and space complexity of traveling salesperson problem.
• Time complexity is O (n2 2n).
• Space complexity is O (n 2n).
14. Define flow shop scheduling.
The processing of jobs requires the performance of several distinct job. In flow shop we have n
jobs each requiring n tasks i.e. T1i, T2i,…...Tmi, 1<i<n.
15. What are the conditions of flow shop scheduling?
• Let Tji denote jth task of the ith job. Task Tij is to be performed on Pj number of processors
where 1<j<m i.e. number of processors will be equal to number of task
• Any task Tji must be assigned to the processor Pj.
• No processor can have more than one task assigned to it at any time. For any jobI
• processing the task for j>1 cannot be started until T(j-i),i has been completed.
16. Define nonpreemptive schedule.
A non preemptive schedule is a schedule in which the processing of a task on any processor is
not terminated until the task is complete.
17. Define preemptive schedule.
A preemptive schedule is a schedule in which the processing of a task on any processor can be
terminated before the task is completed.
18. Define finish time
The finish time fi (S) of job i is the time at which all tasks of job i have been completed in
schedule S.The finish time F(S) of schedule S is given by F(S)=max{ fi (S)} 1<i<n
19. Define mean flow time
The mean flow time MFT (S) is defined to be]
MFT (S) = 1 Sfi(S)
n 1<i<n
20. Define optimal finish time.
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
Optimal finish time scheduling for a given set of tasks is a nonpreemptive schedule S for which
F (S) is minimum over all nonpreemptive schedules S.
21. Define preemptive optimal finish time.
Preemptive optimal finish time scheduling for a given set of tasks is a preemptive schedule S for
which F (S) is minimum over all preemptive schedules S.
22. What are the requirements that are needed for performing Backtracking?
To solve any problem using backtracking, it requires that all the solutions satisfy a complex set
of constraints. They are:
i. Explicit constraints.
ii. Implicit constraints.
23. Define explicit constraint.
They are rules that restrict each xi to take on values only from a give set. They depend on the
particular instance I of the problem being solved. All tuples that satisfy the explicit constraints
define a possible solution space.
24. Define implicit constraint.
They are rules that determine which of the tuples in the solution space of I satisfy the criteria
function. It describes the way in which the xi must relate to each other.
25. Define state space tree.
The tree organization of the solution space is referred to as state space tree.
26. Define state space of the problem.
All the paths from the root of the organization tree to all the nodes is called as state space of the
problem.
27. Define answer states.
Answer states are those solution states s for which the path from the root to s defines a tuple that
is a member of the set of solutions of the problem.
28. What are static trees?
The tree organizations that are independent of the problem instance being solved are called as
static tree.
29. What are dynamic trees?
The tree organizations those are independent of the problem instance being solved are called as
static tree.
30. Define a live node.
A node which has been generated and all of whose children have not yet been generated is called
as a live node.
31. Define a E – node.
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
E – node (or) node being expanded. Any live node whose children are currently being generated
is called as a E – node.
32. Define a dead node.
Dead node is defined as a generated node, which is to be expanded further all of whose children
have been generated.
33. 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.
34. 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
35. 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.
36. 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
37. 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.
38. 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
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
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.
39. 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.
40. Define brute force string matching.
The brute force string matching has a given string of n characters called the text and a string of m
characters called the pattern, find a substring of the text that matches the pattern. And find the
index I of the leftmost character of the first matching substring in the text.
41. 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
42. Define merge sort.
Merge sort sorts a given array A[0..n-1] by dividing it into two halves a[0..(n/2)-1] and A[n/2..n1] sorting each of them recursively and then merging the two smaller sorted arrays into a single
sorted one.
43. What is the difference between quick sort and merge sort?
Both quicksort and mergesort use the divide-and-conquer technique in which the given array is
partitioned into sub arrays 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.
44. What is decrease and conquer approach and mention its variations?
The decrease and conquer technique based on exploiting the relationship between a solution to a
given instance of a problem and a solution to a smaller instance of the same problem. The three
major variations are
* Decrease by a constant
* Decrease by a constant-factor
* Variable size decrease
45. What is insertion sort?
Insertion sort in an application of decrease-by-one technique to sort an array A[0..n-1]. We
assume that the smaller problem of sorting an array A[0..n-2] has already been solved to give us
a sorted array of size n-1. Then an appropriate position for A[n-1] is found among the sorted
element and then the element is inserted.
46. What is a tree edge and back edge?
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
In the depth first search forest, whenever a new unvisited vertex is reached for the first
time, it is attached as a child to the vertex from which it is being reached. Such an edge is called
tree edge because the set of all such edges forms a forest. The algorithm encounters an edge
leading to a previously visited vertex other than its immediate predecessor. Such an edge is
called a back edge because it connects a vertex to its ancestor, other than the parent, in the depth
first search forest.
47. What is a tree edge and cross edge?
In the breadth first search forest, whenever a new unvisited vertex is reached for the first
time, it is attached as a child to the vertex from which it is being reached. Such an edge is called
tree edge. If an edge is leading to a previously visited vertex other than its immediate
predecessor that edge is noted as cross edge.
48. Mention an algorithm to find out the height of a binary tree.
ALGORITHM Height(T)
//Compares recursively the height of a binary tree
//Input: A binary tree T
//Output: The height of T
if T = return -1
else return max{Height(TL), Height(TR)}+1
49. 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 KA[m]
UNIT IV
1. What is transform and conquer technique?
The group of design techniques that are based on the idea of transformation is called
transform and conquer technique because the methods work as two stage procedures. First in the
transformation stage, the problem’s instance is modified to be more amenable (agreeable) to
the solution. Then in the second or conquering stage, it is solved.
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
2. What are the three variations by which a given instance of a problem is transformed
into?
The three major variations are
Transformation to a different representation of the same instance called representation change
Transformation to an instance of a different problem for which the algorithm is already available
called problem reduction.
3. What is presorting?
Presorting is the idea of sorting a list so that problems can be solved more easier than in an
unsorted list. The time efficiency of the algorithm that involves sorting before solving the
problem depends on the sorting algorithm being used.
4. Compare the efficiency of solving the problem of element uniqueness using presorting
and without sorting the elements of the array?
The brute force algorithm compares pairs of the array's elements until either two equal elements
were found or no more pairs were left. It's worst case efficiency was in (n2).
The running time of the presorted algorithm depends on the time spent on sorting and the time
spent on checking consecutive elements. The worst case efficiency of the entire presorting based
algorithm will be as follows
T(n) = Tsort(n)+Tscan(n)  (n log n) + (n) = (n log n)
5. Compare the efficiencies of the algorithms used to compute the mode before and after
sorting the array of elements.
The efficiency of computing the mode before sorting the array for the worst case is a list
with no equal elements. For such a list the Ith element is compared with I-1 elements of the
auxiliary list of distinct values seen so far before being added to the list with a frequency of 1.
The worst case number of comparisons made by the algorithm in creating the frequency list is
(n2).
The analysis of the presorted algorithm will be dominated by the time spent on sorting
the list, since the remainder time to search the frequency list takes only linear time. So the
efficiency class for the algorithm is (n log n).
6. What are binary search trees and what is it mainly used for?
Binary search trees is one of the principal data structures for implementing dictionaries. It
is a binary tree whose nodes contain elements of a set of orderable items, one element per node,
so that all elements in the left subtree are smaller than the element in the subtree’s root and
all elements in the right subtree are greater than it.
7. Define AVL trees and who was it invented by?
An AVL tree is a binary search tree in which the balance factor of every node, which is
defined as the difference between the heights of the node's left and right subtrees, is either 0 or
+1 or –1. the height of an empty subtree is defined as –1. AVL trees were invented in 1962
by two Russian scientists, G.M.Adelson-Velsky and E.M.Landis, after whom the data struture is
named.
8. What is a rotation in AVL tree used for?
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
If an insertion of a new node makes an AVL tree unbalanced, the tree is transformed by a
rotation. A rotation in an AVL tree is a local transformation of its subtree rooted at a node whose
balance has become either +2 or –2; if there are several such nodes, then the tree rooted at the
unbalanced node that is closest to the newly inserted leaf is rotated.
9. What are the drawbacks of AVL trees?
The drawbacks of AVL trees are
Frequent rotations
The need to maintain balances for the tree's nodes
Overall complexity, especially of the deletion operation.
10. What are the types of rotation?
There are four types of rotations, in which two of them are the mirror images of the other two
rotations. The four rotations are
Single right rotation or R-rotation
Single left rotation or L-rotation
Double left-right rotation or LR-rotation
Double right-left rotation or RL-rotation
11. What is a heap?
A heap is a partially ordered data structure, and can be defined as a binary tree assigned
to its nodes, one key per node, provided the following two conditions are met
The tree's shape requirement-The binary tree is essentially complete, that is all the leaves are full
except possibly the last level, where only some rightmost leaves will be missing.
The parental dominance requirement-The key at each node is greater than or equal to the keys of
its children
12. What is the main use of heap?
Heaps are especially suitable for implementing priority queues. Priority queue is a set of items
with orderable characteristic called an items priority, with the following operations
Finding an item with the highest priority
Deleting an item with highest priority
Adding a new item to the set
13. Give three properties of heaps?
The properties of heap are
There exists exactly one essentially complete binary tree with 'n' nodes.
Its height is equal to log2n
The root of the heap is always the largest element
A node of a heap considered with all its descendants is also a heap
14. What are the two alternatives that are used to construct a heap?
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
The two alternatives to construct a heap are
Bottom-up heap construction
Top-down heap construction
15. 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.
16. 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
17. What are the factors that influence the efficiency of the backtracking algorithm?
The efficiency of the backtracking algorithm depends on the following four factors. They are:
i. The time needed to generate the next xk
ii. The number of xk satisfying the explicit constraints.
iii. The time for the bounding functions Bk
iv. The number of xk satisfying the Bk.
18. Define Branch-and-Bound method.
The term Branch-and-Bound refers to all the state space methods in which all children of the Enode are generated before any other live node can become the E- node.
19. What are the searching techniques that are commonly used in Branch-and-Bound
method?
The searching techniques that are commonly used in Branch-and-Bound method are:
i. FIFO
ii. LIFO
iii. LC
iv. Heuristic search
20. State 8 – Queens problem.
The problem is to place eight queens on a 8 x 8 chessboard so that no two queen “attack” that is,
so that no two of them are on the same row, column or on the diagonal.
21. State Sum of Subsets problem.
Given n distinct positive numbers usually called as weights, the problem calls for finding all the
combinations of these numbers whose sums are m.
22. State m – colorability decision problem.
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
Let G be a graph and m be a given positive integer. We want to discover whether the nodes of G
can be colored in such a way that no two adjacent nodes have the same color yet only m colors
are used.
23. Define chromatic number of the graph.
The m – colorability optimization problem asks for the smallest integer m for which the graph G
can be colored. This integer is referred to as the chromatic number of the graph.
24. Define a planar graph.
A graph is said to be planar if it can be drawn in such a way that no two edges cross each other.
25. What are NP- hard and Np-complete problems?
The problems whose solutions have computing times are bounded by polynomials of small
degree.
26. What is a decision problem?
Any problem for which the answer is either zero or one is called decision problem.
Unit – V
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
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
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. 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.
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
9. 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'.
10. 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+1d (the sum s' is too large)
s'+ sjd (the sum s' is too small)
11. 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.
12. 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.
Reassign values to one or more components of a solution
rearranging the data of a given instance.
13. 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)
14. 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.
15. 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.
16. Compare backtracking and branch-and-bound.
Backtracking Branch-and-bound
State-space tree is constructed using depth-first search State-space tree is constructed using best-
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Vi Institute of Technology
Department of Computer Science
Question Bank
first search
Finds solutions for combinatorial non-optimization problems Finds solutions for combinatorial
optimization problems
No bounds are associated with the nodes in the state-space tree Bounds are associated with the
each and every node in the state-space tree
17. 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.
18. 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.
19. 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.
20. 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.
CS2251 –DESIGN AND ANALYSIS OF ALGORITHM
Download