DAA Unit 1
DAA Unit 1
DAA Unit 1
2 marks
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 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
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 precisethan 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 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
13. 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.
14. 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
15. 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.
16. 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.
17. 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.
18. 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.
19. 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.
20. 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 non-negative integer n 0
such that
T (n) <=cg (n) for all n >= n0
21. 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 non-negative
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 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
23. 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.
24. 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 : n3
Exponential : 2n
Factorial : n!
25. 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.
26. 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
27. What is order of growth?
Measuring the performance of an algorithm based on the input size n is called order of growth.
16 marks
600
500
n*n*
400 n
n*n
300 n
log(n)
n
200
100
0
1 2 3 4 5 6 7 8
M(n) ∈ Θ (n)
M(0) = 0
Analysis:
For sequential search, best-case inputs are lists of size n with their first elements equal to a search key;
accordingly,
Cbw(n) = 1.
Average Case Analysis:
The standard assumptions are that
(a) the probability of a successful search is equal top (0 <=p<-=1) and
(b) the probability of the first match occurring in the ith position of the list is the same for every
i. Under these assumptions- the average number of key comparisons Cavg(n) is found as follows.
In the case of a successful search, the probability of the first match occurring in the i th position of
the list is p / n for every i, and the number of comparisons made by the algorithm in such a situation is
obviously i. In the case of an unsuccessful search, the number of comparisons is n with the probability of
such a search being (1- p). Therefore,
For example, if p = 1 (i.e., the search must be successful), the average number of key comparisons made
by sequential search is (n + 1) /2; i.e., the algorithm will inspect, on average, about half of the list's elements.
If p = 0 (i.e., the search must be unsuccessful), the average number of key comparisons will be n because the
algorithm will inspect all n elements on all such inputs.
9. Explain in detail about Tower of Hanoi.
In this puzzle, there are n disks of different sizes and three pegs. Initially, all the disks are on the first
peg in order of size, the largest on the bottom and the smallest on top. The goal is to move all the disks to the
third peg, using the second one as an auxiliary, if necessary. On1y one disk can be moved at a time, and it is
1 3
2
forbidden to place a larger disk on top of a smaller one.
= 2n-1