Comp CH4-1
Comp CH4-1
COMPUTATIONAL COMPLEXITY
Computational Complexity
Basics of algorithm analysis: Big O-notation
P vs NP Un-decidable problems
Cook’s theorem
Computational Complexity
It is an important part of computational complexity
theory, which provides theoretical estimation for the
required resources of an algorithm to solve a specific
computational problem.
If we compare bubble sort and merge sort. Bubble sort does not
require additional memory, but merge sort requires additional
space.
Proof by Induction:- Using mathematical induction, we can prove an algorithm is correct for all the inputs
by proving it is correct for a base case input, say 1, and assume it is correct for another input k, and then
prove it is true for k+1.
Proof by Loop Invariant :- Find a loop invariant k, prove that the base case holds true for the loop invariant
in the algorithm. Then apply mathematical induction to prove the rest of algorithm true.
Methodology of Analysis
Asymptotic Analysis:-
The asymptotic behavior of a function f(n) refers to the growth of f(n) as n
gets large.
A good rule of thumb is that the slower the asymptotic growth rate, the better
the algorithm. Though it’s not always true
Methodology of Analysis
Solving Recurrence Equations:-
Recursion Tree Method − In this method, a recurrence tree is formed where each
node represents the cost.
Accounting Method:-
Dynamic Table:-
If the allocated space for the table is not enough, we must copy the table
into larger size table. Similarly, if large number of members are erased
from the table, it is a good idea to reallocate the table with a smaller size.
Big-O Notation
Big O notation is a mathematical notation that describes the limiting
behavior of a function when the argument tends towards a particular value
or infinity.
Is Big-O Useful?
It provides an upper limit on the time taken by an algorithm in terms of the size of
the input.
It’s denoted as O(f(n)), where f(n) is a function that represents the number of
operations (steps) that an algorithm performs to solve a problem of size n.
Big O notation only describes the asymptotic behavior of a function, not its exact
value.
The Big O notation can be used to compare the efficiency of different algorithms or
data structures
Definition of Big-O Notation:
Given two functions f(n) and g(n),
we say that f(n) is O(g(n)) if there exist constants c > 0 and n0 >= 0 such that
f(n) <= c*g(n) for all n >= n0.
Transitivity
If f(n) = O(g(n)) and g(n) = O(h(n)), then f(n) = O(h(n)).
Constant Factor
for any constant c > 0 and functions f(n) and g(n), if f(n) =
O(g(n)), then c*f(n) = O(g(n)).
Properties of Big O Notation:
Sum Rule
Product Rule
If f(n) = O(g(n)) and h(n) = O(k(n)), then f(n) * h(n) = O(g(n) * k(n)).
Composition Rule
include linear time complexity O(n), quadratic time complexity O(n2), and
cubic time complexity O(n3).