0.0 Definition of Algorithm
0.0 Definition of Algorithm
of CSE, SRM AP
o Algorithm
o Complexitie
s
What is an algorithm
Brassard and Brately coined the term algorithmics,
which they defined as “the systematic study of the
fundamental techniques used to design and analyze
the efficient algorithms”.
Verbal Visual
o Flow Chart
o Pseudo Code o FSM Diagram
o UML Diagram
Condition:
Pre Condition(s) – lists any precursor requirements
for the parameters. Sometimes there might be no
parameters also.
Post Condition – identifies any action taken and the
status of any output parameter.
Return: If a value is written by the algorithm, then it
is identified by a RETURN condition.
Statement Constructs
CHANDRA SEKHAR.CH AP19110010028
Structure of an Algorithm
1. Input Step
2. Assignment Step
3. Decision Step
4. Repetitive
5. Output Step
…
for k = 1 to n do (n+1)
x = x + 2; n
end n
… ----------------------------------------
Total: (n+1) + n + n = 3n+1 = n
…
for j = 1 to n do (n+1)
for k = 1 to n n2
do
x=x+2
end
n
end ------------------------------------------------
… Total: (n+1)+(n+1)(n)+(n2 )+(n2)+(n) = 3n2+3n+1 = n2
Tips on mathematical formulae.
Definition-1:
f(x) = O(g(n)) – read as “f of n is big oh of g of n.
If there exists a positive integer n0 and a positive
number C such that |f(n)| ≤ c |g(n)|, for all n ≥ no ;
and for C > 0 and no ≥ 1
E.g.,
Definition-2:
f(x) = Ω(g(n)) – read as “f of n is omega of g of n.
If there exists a positive integer n0 and a positive
number C such that |f(n)| ≥ c |g(n)|, for all n ≥ no
E.g.,
f(n) g(n) Complexity
16n3 + 8n2 + 12 n3 f(n) = Ω(n3)
24n – 9 n f(n) = Ω (n)
Asymptotic Notations
Definition-3:
f(x) = θ(g(n)) – read as “f of n is theta of g of n.
If there exists a positive integer n0 and two positive constants
C1 and C2 such that
C1|g(n)| ≤ |f(n)| ≤ C2|g(n)|, for all n ≥ no
E.g.,
Measures of efficiency
Growth Rate: θ Notation
Growth rate
Growth Rate: θ Notation