CS8451 DAA Unit I Notes

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

1

ANNA UNIVERSITY, CHENNAI


AFFILIATED INSTITUTIONS
R-2013
Computer Science and Engineering
CS6402 DESIGN AND ANALYSIS OF ALGORITHMS
IV SEM CSE
UNIT-1 Notes
1) What is a Computer Algorithm?
An algorithm is a sequence of unambiguous nstructions for solving a problem, i.e., for
obtaining a required output for any legitimate input in a finite amount of time.

2) What are the features of an algorithm?


• More precisely, an algorithm is a method or process to solve a problem satisfying
the following properties:
– Finiteness
• terminates after a finite number of steps
– Definiteness
• Each step must be rigorously and unambiguously specified.
-e.g., ”stir until lumpy”
– Input
• Valid inputs must be clearly specified.
– Output
• can be proved to produce the correct output given a valid can be
proved to produce the correct output given a valid input.
– Effectiveness
• Steps must be sufficiently simple and basic.

3) Show the notion of an algorithm.

4) What are different problem types?


2

5) What are different algorithm design techniques/strategies?

• Brute force

• Divide and conquer

• Decrease and conquer

• Transform and conquer


• Space and time tradeoffs
• Greedy approach

• Dynamic programming
• Backtracking
• Branch and bound

6) What are fundamental data structures?

• list
– array
– linked list
– string
• stack
• queue
• priority queue
• graph
• tree
• set and dictionary

7) What are the sequence of steps in designing and analyzing the algorithm?

Fundamentals of Algorithmic Problem Solving


• Understanding the problem
– Asking questions, do a few examples by hand, think about special cases,
etc.
• Deciding on
3

– Exact vs. approximate problem solving


– Appropriate data structure
• Design an algorithm
• Proving correctness
• Analyzing an algorithm
– Time efficiency : how fast the algorithm runs
– Space efficiency: how much extra memory the algorithm needs.
• Coding an algorithm

8) What is algorithm analysis framework?


Analysis of algorithms means to investigate an algorithm’s efficiency with respect to
resources: running time and memory space
Time efficiency: how fast an algorithm runs.
Space efficiency: the space an algorithm requires.
• Typically, algorithms run longer as the size of its input increases
• We are interested in how efficiency scales wrt input size
Analysis Framework
4

Measuring an input’s size


Measuring running time
Orders of growth (of the algorithm’s efficiency function)
Worst-base, best-case and average-case efficiency
9) How the running time of an algorithm is measured?
Units for Measuring Running Time
Count the number of times an algorithm’s basic operation is executed.
 Basic operation: the operation that contributes the most to the total
running time.
 For example, the basic operation is usually the most time-consuming
operation in the algorithm’s innermost loop.
10) How time effieciency is analysed?
Time efficiency is analyzed by determining the number of repetitions of the basic
operation as a function of input size.

input
size

T(n) ≈ copC (n)


running execution time Number of times the
time for the basic basic operation is
operation executed

11) What is orders of growth?

Orders of Growth

12) What are Worst-Case, Best-Case, and Average-Case Efficiency ?


Worst case Efficiency
 Efficiency (# of times the basic operation will be executed) for the worst
case input of size n.
5

 The algorithm runs the longest among all possible inputs of size n.
Best case
 Efficiency (# of times the basic operation will be executed) for the best
case input of size n.
 The algorithm runs the fastest among all possible inputs of size n.
Average case:
 Efficiency (#of times the basic operation will be executed) for a
typical/random input of size n.
 NOT the average of worst and best case
 How to find the average case efficiency?
13) What are asymptotic notations? Explain in detail.
Asymptotic Growth Rate
Three notations used to compare orders of growth of an algorithm’s basic
operation count
 O(g(n)): class of functions f(n) that grow no faster than g(n)
 Ω(g(n)): class of functions f(n) that grow at least as fast as g(n)
 Θ (g(n)): class of functions f(n) that grow at same rate as g(n)

O-notation

Formal definition
 A function t(n) is said to be in O(g(n)), denoted 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 exist some positive constant c and some nonnegative integer n0 such
that
t(n)  cg(n) for all n  n0
6

-notation

Formal definition
 A function t(n) is said to be in (g(n)), denoted 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 exist some positive constant c and some nonnegative integer n0 such
that
t(n)  cg(n) for all n  n0

-notation

Formal definition
 A function t(n) is said to be in (g(n)), denoted t(n)  (g(n)), if t(n) is
bounded both above and below by some positive constant multiples of
g(n) for all large n, i.e., if there exist some positive constant c1 and c2 and
some nonnegative integer n0 such that
c2 g(n)  t(n)  c1 g(n) for all n  n0
7

14) What are basic efficiency classes?


Basic Efficiency classes

1 constant

log n logarithmic

n linear

n log n n log n

n2 Basic Efficiency quadratic


classes

n3 cubic

2n exponential

n! factorial

15) Give an example for basic operations.


Input size and basic operation examples

Problem Input size measure Basic operation

Searching for key in a Number of list’s items,


Key comparison
list of n items i.e. n
8

Multiplication of two Matrix dimensions or Multiplication of two


matrices total number of elements numbers

Checking primality of n’size = number of digits


Division
a given integer n (in binary representation)

Visiting a vertex or
Typical graph problem #vertices and/or edges
traversing an edge

16) Write an algorithm for counting binary digits for a decimal number.

17) Write an algorithm for matrix multiplication.

You might also like