0% found this document useful (0 votes)
27 views

Complexity Analysis

Ursutxiycoucpivivpuvpuvpuvpu

Uploaded by

Sahar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Complexity Analysis

Ursutxiycoucpivivpuvpuvpuvpu

Uploaded by

Sahar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Complexity Analysis

ALGORITHMS
• STEP BY STEP PROCEDURE TO SOLVE A PROBLEM
• USED IN DAILY LIFE PROBLEMS
• IN CS, ALGORITHM IS DEFINED BY:
1- MUST HAVE SOME DATA TO OPERATE ON IT
2- MUST PRODUCE ATLEAST ONE RESULT
3- MUST TERMINATE AFTER FINITE NUMBER OF STEPS
• MANY ALGORITHMS HAVE BEEN DESIGNED
• Searching algorithms
• Sorting algorithms
• Compression algorithms
• Fast Fourier transforms( designed for digital signal processing)
• Encoding algorithms (used for encryption of data)
• Geometric algorithms( used for identification of geometric shapes)
• Pattern matching algorithms ( comparing images and shapes)
Classification of algorithms
• Depending on the strategy for solving a particular algorithms,
algorithms can be classified as:
• 1- Iterative (for example: sorting an array)
• 2 Divide and Conquer
• 3 Greedy algorithm ( an immediately available best solution at each
step is chosen) e.g: which way of conveyance to choose immediately
•4
Specification of algorithms
• Natural language
• Pseudo code

• Natural language: words like read, write, subtract, divide, repeat, for
while are used
• Pseudo code: It is a blend of natural language and programming
notation
Complexity
• Time complexity
• Space complexity
• Input
• Worst-case Complexity: Maximum time required for program
execution (Run slowest among all inputs) In the worst case analysis,
we calculate upper bound on running time of an algorithm.
• Average Complexity: Average time required for program execution.
Gives the necessary information about algorithm’s behavior on
random input.
• Best Case: Minimum time required for program execution (Run
Fastest among all inputs). It gives lower bound on running time of
algorithm for any instances of input.
• Why Worst Case Analysis?
The worst-case running time of an algorithm gives an upper bound on
the running time for any input. Knowing it provides a guarantee that
the algorithm will never take any longer.For some algorithms, the
worst case occurs fairly often. For example, in searching a database
for a particular piece of information, the searching algorithm’s worst
case will often occur when the information is not present in the
database.
• The “average case” is often roughly as bad as the worst case.
Method Worst case Average case
Selection sort N2 N2

Insertion sort N2 N2
Merge sort Nlogn Nlogn

Quick sort n2 nlogn


• Asymptotic notations give time complexity as “fastest possible”,
“slowest possible” or “average time”.
Asymptotic Notations
• Following are commonly used asymptotic notations used in calculating running
time complexity of an algorithm.
• 1. Big O Notationf(n)=O(g(n)) (read: 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≥n0.
• 2. Omega (Ω) Notationf(n)=Ω(g(n))(read: f of n is omega of g of n), if there exists a
positive integer n0 and a positive integer c such that |f(n)|≥c|g(n)|, for all n≥n0.
• 3. Theta (θ) Notationf(n)= Ө(g(n))(read: f of n is thita of g of n), if there exists a
positive integer n0 and a positive integer c1 and c2 such that c1|g(n)| ≤ |f(n)|
≤c2|g(n)|, for all n≥n0.
Big oh notation
• The Ο(n) is the formal way to express the upper bound of an
algorithm's running time.It always indicates the maximum time
required by an algorithm for all input values.That means Big - Oh
notation describes the worst case of an algorithm time
complexity.Definition:O(g(n)) = {f(n) : there exists positive constants c
and n0 such that 0 ≤ f(n) ≤ c g(n) for all n ≥ n0.
• Omega ( )notation (lower bound- best case )
 -notation provides an asymptotic lower bound on a function.It
measures the best case time complexity or best amount of time an
algorithm can possibly take to complete.Definition:
• It measures the Average case Complexity.
2. Theta (θ)notation(upper bound as well as lower bound – Average
case )The θ(n) is the formal way to express both the lower bound and
upper bound of an algorithm's running time. It measures the Average
case Complexity.

You might also like