Design and Analysis of Algorithm SNSCT – Department of Compute Science and Engineering Page 1 SNS COLLEGE OF TECHNOLOGY COIMBATORE – 35 DEPARTMENT OF COMPUTER SIENCE AND ENGINEERING (UG & PG) Second Year Computer Science and Engineering, 4rd Semester 2 Marks Question and Answer Subject Code & Name: Design and Analysis of Algorithm Prepared by: J. kasthuri L/CSE, S.P Siddque Ibrahim L/CSE UNIT – I 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
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Design and Analysis of Algorithm
SNSCT – Department of Compute Science and Engineering Page 1
SNS COLLEGE OF TECHNOLOGY
COIMBATORE – 35
DEPARTMENT OF COMPUTER SIENCE AND ENGINEERING (UG & PG)
Second Year Computer Science and Engineering, 4rd Semester
2 Marks Question and Answer
Subject Code & Name: Design and Analysis of Algorithm
Prepared by: J. kasthuri L/CSE, S.P Siddque Ibrahim L/CSE
UNIT – I
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 >
}
Design and Analysis of Algorithm
SNSCT – Department of Compute Science and Engineering Page 2
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)
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
instances
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.
Design and Analysis of Algorithm
SNSCT – Department of Compute Science and Engineering Page 3
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))
Iff Lim f(n) = 0
n - μ g(n)
18. Define Little Omega.
The function f(n) = w (g(n))
iff
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
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
Design and Analysis of Algorithm
SNSCT – Department of Compute Science and Engineering 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.
26. What is classification of the recurrence equation?
Recurrence Equations can be classified into
1. Homogeneous
2. Inhomogeneous
Design and Analysis of Algorithm
SNSCT – Department of Compute Science and Engineering Page 5
12 mark Questions
Unit I
1. Define the asymptotic notations used for best case average case and
worst case
analysis of algorithms.
2. Write an algorithm for finding maximum element of an array , perform
best , worst
and average case complexity with appropriate order notations.
3. Write an algorithm to find mean and variance of an array perform best,
worst and
average
4. Explain the various criteria used for analyzing algorithms.
5. List the properties of various asymptotic notations.
6. Explain the necessary steps for analyzing the efficiency of recursive
algorithms.
7. Write short notes on algorithm visualization.
8. Describe briefly the notions of complexity of an algorithm.
9. What is pseudo-code? Explain with an example
10. Find the complexity (C (n))of the algorithm for the worst case, best
case and average
case. (evaluate average case complexity for n = 3,where n is number of
inputs)
Design and Analysis of Algorithm
SNSCT – Department of Compute Science and Engineering Page 6
UNIT II
1. Define the divide and conquer method.
Given a function to compute on ‘n’ inputs the divide-and-comquer
strategy
suggests splitting the inputs in to’k’ distinct susbsets, 1<k <n, yielding ‘k’
subproblems. The subproblems must be solved, and then a method must
be found
tocombine 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.
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;