Escolar Documentos
Profissional Documentos
Cultura Documentos
Algorithms (ADA)
Unit - 1
Introduction.
12/08/21 1
Introduction…
Algorithm Design…
Approaches :
1. Brute Force - It can be defined as a straightforward approach
to solving a problem, usually directly based on the problem's statement
and definitions of the concepts involved.
Eg: sum of n numbers, finding the largest element in a list, adding two
matrices, etc.
2. Incremental and
3. Divide & Conquer.
12/08/21 7
Input size and basic operation examples
12/08/21 9
Introduction …
Perrformance cases… :
Performance cases… :
• Average case performance is used to do with
the mathematical average of all cases.
Average performance and worst-case
performance are the most used in
algorithm analysis. Less widely found is
best-case performance but it does have
uses,
for example knowing the best cases of
individual tasks can be used to improve
accuracy of an overall worst-case
analysis.
12/08/21 13
Order of growth
• It is not necessary to compute the efficiency of algorithm for smaller inputs.
• We will find the difference and importance in algorithm’s efficiency only when
the input is large.
• For larger values of n, count depends upon the function’s order of growth.
• Order of growth can be expressed as
1. Logarithmic.
2. Linear.
3. Quadratic.
4. Cubic.
5. Exponential .
6. Factorial.
The function growing slowest among these is Logarithmic function and
exponential , factorial functions grow very fast.
12/08/21 14
Basic asymptotic efficiency classes :
1 constant
log n logarithmic
n linear
n log n n-log-n
n2 quadratic
n3 cubic
2n exponential
n! factorial
12/08/21 15
Values of some important functions as n
12/08/21 16
Asymptotic analysis of algorithms
• We usually embark on an asymptotic worst case analysis
of the running time of the algorithm.
• Asymptotic:
– Formal, exact, depends only on the algorithm.
– Ignores constants.
– Applicable mostly for large input sizes.
• Worst Case:
– Bounds on running time must hold for all inputs.
– Thus the analysis considers the worst-case input.
– Sometimes the “average” performance can be much
better.
– Real-life inputs are rarely “average” in any formal sense.
12/08/21 17
Asymptotic order of growth
To compare and rank the Order of growth of basic
operations count, 3 notations are used. (big oh) ,
(big omega) and (big theta).
12/08/21 18
Big Oh Notation
12/08/21 19
Big-oh Notation
12/08/21 20
-notation
12/08/21 22
-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) f(n) c1 g(n) for all n n0.
– f(n)= (g(n)) means c1.g(n) is an upper bound on f(n)
and c2.g(n) is a lower bound on f(n), for large enough
n. Thus there exists constants c1 and c2 such that
fn c1. g(n) and fn c2. g(n) .
Eg.: f(n)=1/2n(n-1) and g(n)=n2 .Prove f(n) is (g(n)).
12/08/21 23
Theta Notation
12/08/21 24
Using Limits for comparing orders of growth
12/08/21 25
Asymptotic performance
When n gets large enough, a Θ(n2) algorithm always beats a Θ(n3)
algorithm.
• We shouldn’t ignore
asymptotically slower
algorithms, however.
• Real-world design
situations often call for
a careful balancing of
engineering objectives.
• Asymptotic analysis is a
useful tool to help to
structure our thinking.
(END –ada1bca)
12/08/21 26