Algorithm Analysis & Types of Algorithms
Algorithm Analysis & Types of Algorithms
Algorithm Analysis & Types of Algorithms
Types of Algorithms
1
Data Structures & Algorithms
Writing algorithms
2
Data Structures & Algorithms
Writing Algorithms
3
Data Structures & Algorithms
Writing Algorithms
Problem − Design an algorithm to add two numbers and
display the result.
Step 1 − START
Step 2 − declare three integers a, b & c
Step 3 − define values of a & b
Step 4 − add values of a & b
Step 5 − store output of step 4 to c
Step 6 − print c
Step 7 − STOP
4
Data Structures & Algorithms
Writing Algorithms
Algorithms tell the programmers how to code the
program. Alternatively, the algorithm can be written as −
5
Data Structures & Algorithms
Analysis of Algorithms
Asymptotic Analysis
Asymptotic analysis of an algorithm refers to
defining the mathematical framing of its run-time
performance.
Asymptotic analysis is input bound i.e., if there's
no input to the algorithm, it is concluded to work
in a constant time. Other than the "input" all
other factors are considered constant.
6
Data Structures & Algorithms
Analysis of Algorithms
Asymptotic Analysis
Asymptotic analysis refers to computing the
running time of any operation in mathematical
units of computation.
For example, the running time of one operation is computed
as f(n) and may be for another operation it is computed as g(n2).
This means that
First operation running time will increase linearly with the
increase in n
the running time of the second operation will increase
exponentially when n increases.
7
Data Structures & Algorithms
Analysis of Algorithms
Asymptotic Analysis
Usually, the time required by an algorithm falls under
three types −
Best Case − Minimum time required for program execution.
Average Case − Average time required for program execution.
Worst Case − Maximum time required for program execution.
Asymptotic Notations
Following are the commonly used asymptotic notations
to calculate the running time complexity of an algorithm.
Ο Notation (big O notation)
Ω Notation (Omega notation)
θ Notation (Theta notation)
8
Data Structures & Algorithms
Analysis of Algorithms
Reading Assignment : Calculations of running time
complexity of algorithms
9
Data Structures & Algorithms
Types of algorithms
10
Data Structures & Algorithms
Types of algorithms
Greedy Algorithms
Divide and Conquer Algorithms
Dynamic Programming
11
Data Structures & Algorithms
Types of algorithms
Greedy Algorithms
In greedy algorithm approach:
Decisions are made from the given solution domain.
As being greedy, the closest solution that seems to
provide an optimum solution is chosen.
Greedy algorithms try to find a localized optimum
solution
Which may eventually lead to globally optimized
solutions. However, generally greedy algorithms do
not provide globally optimized solutions.
12
Data Structures & Algorithms
Types of algorithms
13
Data Structures & Algorithms
Types of algorithms
14
Data Structures & Algorithms
Types of algorithms
Knapsack Problem
15
Data Structures & Algorithms
Types of algorithms
16
Data Structures & Algorithms
Types of algorithms
halves
Recursively sort the two halves
17
Data Structures & Algorithms
Types of algorithms
18
Data Structures & Algorithms
Types of algorithms
19
Data Structures & Algorithms
Types of algorithms
Dynamic Programming
a method for solving a complex problem by breaking it
down into a collection of simpler subproblems, solving
each of those subproblems just once, and storing their
solutions
the next time the same subproblem occurs, instead of
recomputing its solution, one simply looks up the
previously computed solution, thereby saving
computation time. This technique of storing solutions
to subproblems instead of recomputing them is called
memoization.
20
Data Structures & Algorithms
Types of algorithms
Dynamic Programming
Here’s brilliant explanation on concept of
21
Data Structures & Algorithms
Types of algorithms
22