SlideShare a Scribd company logo
Analysis of Algorithms
Introduction
Andres Mendez-Vazquez
September 27, 2015
1 / 36
Outline
1 Motivation
What is an Algorithm?
Instance of a Problem
Kolmogorov’s Definition
2 Problems Solved By Algorithms
What Problems Are Solved By Algorithms?
3 Syllabus
Subjects for the Class
4 Some Notes in Notation
Before Anything, The Notation for Pseudo-Code
5 What abstraction of a Computer to use?
The Random-Access Machine (RAM) Machine
6 Analyzing Algorithms
How Input Size affects Running Time
The First Method: Counting Number of Operations
Counting Equation For Insertion Sort
The Analysis of the Best and Worst Case Inputs
2 / 36
Outline
1 Motivation
What is an Algorithm?
Instance of a Problem
Kolmogorov’s Definition
2 Problems Solved By Algorithms
What Problems Are Solved By Algorithms?
3 Syllabus
Subjects for the Class
4 Some Notes in Notation
Before Anything, The Notation for Pseudo-Code
5 What abstraction of a Computer to use?
The Random-Access Machine (RAM) Machine
6 Analyzing Algorithms
How Input Size affects Running Time
The First Method: Counting Number of Operations
Counting Equation For Insertion Sort
The Analysis of the Best and Worst Case Inputs
3 / 36
Introduction
Informal definition
Informally, an algorithm is any well defined computational procedure that
It takes some value, or set of values, as input.
Then, it produces some value, or set of values, as output.
Examples
4 / 36
Introduction
Informal definition
Informally, an algorithm is any well defined computational procedure that
It takes some value, or set of values, as input.
Then, it produces some value, or set of values, as output.
Examples
4 / 36
Introduction
Informal definition
Informally, an algorithm is any well defined computational procedure that
It takes some value, or set of values, as input.
Then, it produces some value, or set of values, as output.
Examples
4 / 36
Introduction
Informal definition
Informally, an algorithm is any well defined computational procedure that
It takes some value, or set of values, as input.
Then, it produces some value, or set of values, as output.
Examples
ALGORITHMINPUT Cluster 1 (7)
OUTPUT
4 / 36
Example
Sorting Problem
Input: A sequence of N numbers a1, a2, ..., aN
Output: A reordering of the input sequence a(1), a(2), ..., a(N)
Actually
We are dealing with instances of a problem.
5 / 36
Example
Sorting Problem
Input: A sequence of N numbers a1, a2, ..., aN
Output: A reordering of the input sequence a(1), a(2), ..., a(N)
Actually
We are dealing with instances of a problem.
5 / 36
Outline
1 Motivation
What is an Algorithm?
Instance of a Problem
Kolmogorov’s Definition
2 Problems Solved By Algorithms
What Problems Are Solved By Algorithms?
3 Syllabus
Subjects for the Class
4 Some Notes in Notation
Before Anything, The Notation for Pseudo-Code
5 What abstraction of a Computer to use?
The Random-Access Machine (RAM) Machine
6 Analyzing Algorithms
How Input Size affects Running Time
The First Method: Counting Number of Operations
Counting Equation For Insertion Sort
The Analysis of the Best and Worst Case Inputs
6 / 36
Instance of a Problem
Instance of the problem
For example, we have
9, 8, 5, 6, 7, 4, 3, 2, 1
Then, we finish with
1, 2, 3, 4, 5, 6, 7, 8, 9
7 / 36
Although Instances are Important
Nevertheless
The way we use those instances is way more important
For example
Look at Recursive Fibonacci!!!
8 / 36
Although Instances are Important
Nevertheless
The way we use those instances is way more important
For example
Look at Recursive Fibonacci!!!
8 / 36
Example: Fibonacci
Fibonacci rule
Fn =



Fn−1 + Fn−2 if n > 1
1 if n = 1
0 if n = 0
Time Complexity
1 Naive version using directly the recursion - exponential time.
2 A more elegant version - linear time.
9 / 36
Example: Fibonacci
Fibonacci rule
Fn =



Fn−1 + Fn−2 if n > 1
1 if n = 1
0 if n = 0
Time Complexity
1 Naive version using directly the recursion - exponential time.
2 A more elegant version - linear time.
9 / 36
Outline
1 Motivation
What is an Algorithm?
Instance of a Problem
Kolmogorov’s Definition
2 Problems Solved By Algorithms
What Problems Are Solved By Algorithms?
3 Syllabus
Subjects for the Class
4 Some Notes in Notation
Before Anything, The Notation for Pseudo-Code
5 What abstraction of a Computer to use?
The Random-Access Machine (RAM) Machine
6 Analyzing Algorithms
How Input Size affects Running Time
The First Method: Counting Number of Operations
Counting Equation For Insertion Sort
The Analysis of the Best and Worst Case Inputs
10 / 36
Kolmogorov’s Definition
A bound for each sub-step
An algorithmic process splits into steps whose complexity is bounded in advance
i.e., the bound is independent of the input and the current state of the
computation.
Transformations done at each step
Each step consists of a direct and immediate transformation of the current state.
This transformation applies only to the active part of the state and does not alter
the remainder of the state.
Size of the steps
The size of the active part is bounded in advance.
Ending the Process
The process runs until either the next step is impossible or a signal says the
solution has been reached.
11 / 36
Kolmogorov’s Definition
A bound for each sub-step
An algorithmic process splits into steps whose complexity is bounded in advance
i.e., the bound is independent of the input and the current state of the
computation.
Transformations done at each step
Each step consists of a direct and immediate transformation of the current state.
This transformation applies only to the active part of the state and does not alter
the remainder of the state.
Size of the steps
The size of the active part is bounded in advance.
Ending the Process
The process runs until either the next step is impossible or a signal says the
solution has been reached.
11 / 36
Kolmogorov’s Definition
A bound for each sub-step
An algorithmic process splits into steps whose complexity is bounded in advance
i.e., the bound is independent of the input and the current state of the
computation.
Transformations done at each step
Each step consists of a direct and immediate transformation of the current state.
This transformation applies only to the active part of the state and does not alter
the remainder of the state.
Size of the steps
The size of the active part is bounded in advance.
Ending the Process
The process runs until either the next step is impossible or a signal says the
solution has been reached.
11 / 36
Kolmogorov’s Definition
A bound for each sub-step
An algorithmic process splits into steps whose complexity is bounded in advance
i.e., the bound is independent of the input and the current state of the
computation.
Transformations done at each step
Each step consists of a direct and immediate transformation of the current state.
This transformation applies only to the active part of the state and does not alter
the remainder of the state.
Size of the steps
The size of the active part is bounded in advance.
Ending the Process
The process runs until either the next step is impossible or a signal says the
solution has been reached.
11 / 36
Kolmogorov’s Definition
A bound for each sub-step
An algorithmic process splits into steps whose complexity is bounded in advance
i.e., the bound is independent of the input and the current state of the
computation.
Transformations done at each step
Each step consists of a direct and immediate transformation of the current state.
This transformation applies only to the active part of the state and does not alter
the remainder of the state.
Size of the steps
The size of the active part is bounded in advance.
Ending the Process
The process runs until either the next step is impossible or a signal says the
solution has been reached.
11 / 36
Kolmogorov’s Definition
A bound for each sub-step
An algorithmic process splits into steps whose complexity is bounded in advance
i.e., the bound is independent of the input and the current state of the
computation.
Transformations done at each step
Each step consists of a direct and immediate transformation of the current state.
This transformation applies only to the active part of the state and does not alter
the remainder of the state.
Size of the steps
The size of the active part is bounded in advance.
Ending the Process
The process runs until either the next step is impossible or a signal says the
solution has been reached.
11 / 36
BTW
How do they look this machines, this algorithms?
After all we like to see them!!!
12 / 36
An Example of an Algorithm
Insertion Sort Algorithm
Data: Unsorted Sequence A
Result: Sort Sequence A
Insertion Sort(A)
for j ← 2 to lenght(A) do
key ← A[j];
// Insert A[j] into the sorted sequence A[1, ..., j − 1]
i ← j − 1;
while i > 0 and A[i] > key do
A[i + 1] ← A[i];
i ← i − 1;
end
A[i + 1] ← key
end
13 / 36
Outline
1 Motivation
What is an Algorithm?
Instance of a Problem
Kolmogorov’s Definition
2 Problems Solved By Algorithms
What Problems Are Solved By Algorithms?
3 Syllabus
Subjects for the Class
4 Some Notes in Notation
Before Anything, The Notation for Pseudo-Code
5 What abstraction of a Computer to use?
The Random-Access Machine (RAM) Machine
6 Analyzing Algorithms
How Input Size affects Running Time
The First Method: Counting Number of Operations
Counting Equation For Insertion Sort
The Analysis of the Best and Worst Case Inputs
14 / 36
Problems Solved By Algorithms
Single-Source
Shortest Path.
Solving systems
of linear
equations.
Huffman codes
Matrix
Multiplication
Convex hull
Short Paths in Maps
These algorithms allows to solve the
problem of finding the shortest path
in a map between two addresses.
@Copyright 2010-2011 Daniel Kastl,
Frédéric Junod. Mis à jour le Apr 02, 2012.
15 / 36
Problems Solved By Algorithms
Single-Source
Shortest Path.
Solving systems
of linear
equations.
Huffman codes
Matrix
Multiplication
Convex hull
Inverting Matrices
Normally, given the system Ax = y,
we do not use the inverse A−1, but
the LUP decomposition
L D U R
@Copyright From Wikimedia Commons, the
free media repository
15 / 36
Problems Solved By Algorithms
Single-Source
Shortest Path.
Solving systems
of linear
equations.
Huffman codes
Matrix
Multiplication
Convex hull
Compression Trees
This method is part of the greedy
methods. They are used for
compression, they can achieve 20%
to 90% compression.
8
17
41
24
109
5
3 2 2 2 2
6
2 3 4
7
14
3
22
1 1
2
4
7
2
1111
4 4
' '
'U' 'A' 'L' 'M'
'E'
'D' 'F' 'N'
'S'
'B' 'H'
'O'
'J' 'P' 'R' 'T'
@Copyright From Wikimedia Commons, the
free media repository
15 / 36
Problems Solved By Algorithms
Single-Source
Shortest Path.
Solving systems
of linear
equations.
Huffman codes
Matrix
Multiplication
Convex hull
Fast Multiplication of Matrices
In many algorithms, we want to
multiply different n × n matrices
A11 A12 A21 A22
B11
B12
B21
B22
C11
1
1
C12
1
1
C21
1
1
C22
1
1
1
11
1
1 1
11
1 1
-1-1
1
-1
1
-1
1
-1
1
-1
1 1
-1-1
1
1
-1
-1
1
1
-1
-1
M1 M2 M3 M4 M5 M6 M7
STRASSEN'S ALGORITHM
@Copyright From Wikimedia Commons, the
free media repository
15 / 36
Problems Solved By Algorithms
Single-Source
Shortest Path.
Solving systems
of linear
equations.
Huffman codes
Matrix
Multiplication
Convex hull
Computational Geometry
Given the points in a plane, we want
to find the minimum convex hull that
encloses them.
p0
p1
p2
p3
@Copyright From Wikimedia Commons, the
free media repository
15 / 36
Problems Solved By Algorithms
Synthetic Biology
Pattern Recognition
Databases
Face Recognition
Computational Molecular Engineering
In this field the engineers and biologist try to use the
basis of life to create complex molecular machines.
All these machines will requiere complex algorithms
@Copyright 2002-2013 SYNTHETIC
COMPONENTS NETWORK University of Bristol
16 / 36
Problems Solved By Algorithms
Synthetic Biology
Pattern Recognition
Databases
Face Recognition
Machine Learning
In pattern recognition, we try to find specific
patterns in data.
@2013Copyright Bülent Üstün, Department of
Analytical Chemistry, University of Nijmegen
16 / 36
Problems Solved By Algorithms
Synthetic Biology
Pattern Recognition
Databases
Face Recognition
Partition of the Database Space
A grid file or bucket grid is a point access method:
Query A1 = 'x' and A2 = 6
a f k p z
A2
A1
Grid Array
Pointers to buckets
0 2 7 10 15
Intervals Define
Search Areas
A1
Bucket Accessed
@Copyright Michael Unwalla: A mixed transaction
cost model for coarse grained multi-column
partitioning in a shared-nothing database machine
16 / 36
Problems Solved By Algorithms
Synthetic Biology
Pattern Recognition
Databases
Face Recognition
Person Identification
Facial Recognition measure face landmarks
to indentify different features in the face.
@Copyright 2013 Wouter Alberda, Olaf Kampinga
16 / 36
Outline
1 Motivation
What is an Algorithm?
Instance of a Problem
Kolmogorov’s Definition
2 Problems Solved By Algorithms
What Problems Are Solved By Algorithms?
3 Syllabus
Subjects for the Class
4 Some Notes in Notation
Before Anything, The Notation for Pseudo-Code
5 What abstraction of a Computer to use?
The Random-Access Machine (RAM) Machine
6 Analyzing Algorithms
How Input Size affects Running Time
The First Method: Counting Number of Operations
Counting Equation For Insertion Sort
The Analysis of the Best and Worst Case Inputs
17 / 36
What will you learn in this class?
1 Growth Functions
2 Solving
Recursions
3 Probabilistic
Analysis
4 Sorting
5 Median and
Order Statistics
6 Review of Basic
Data Structures
7 Advanced Data
Structures
8 Advanced
Techniques
Basic Complexities
Asymptotic Notation - Ω, O and
Θ
Standard notation and common
functions.
18 / 36
What will you learn in this class?
1 Growth Functions
2 Solving
Recursions
3 Probabilistic
Analysis
4 Sorting
5 Median and
Order Statistics
6 Review of Basic
Data Structures
7 Advanced Data
Structures
8 Advanced
Techniques
For finding Complexities
The substitution method.
The recursive three method.
The master method.
18 / 36
What will you learn in this class?
1 Growth Functions
2 Solving
Recursions
3 Probabilistic
Analysis
4 Sorting
5 Median and
Order Statistics
6 Review of Basic
Data Structures
7 Advanced Data
Structures
8 Advanced
Techniques
Using Probability for finding
Complexities
Indicator Random Variables.
Randomization Algorithms.
18 / 36
What will you learn in this class?
1 Growth Functions
2 Solving
Recursions
3 Probabilistic
Analysis
4 Sorting
5 Median and
Order Statistics
6 Review of Basic
Data Structures
7 Advanced Data
Structures
8 Advanced
Techniques
Sorting Thecniques
Heapsort.
Quicksort.
Sorting in linear time.
18 / 36
What will you learn in this class?
1 Growth Functions
2 Solving
Recursions
3 Probabilistic
Analysis
4 Sorting
5 Median and
Order Statistics
6 Review of Basic
Data Structures
7 Advanced Data
Structures
8 Advanced
Techniques
Finding Order
Minimum and Maximum.
Selection.
Worst Case Selection.
18 / 36
What will you learn in this class?
1 Growth Functions
2 Solving
Recursions
3 Probabilistic
Analysis
4 Sorting
5 Median and
Order Statistics
6 Review of Basic
Data Structures
7 Advanced Data
Structures
8 Advanced
Techniques
Basic Data Structures
Elementary data structures.
Hash tables.
Applications of Hash Tables
Linear Counting
Binary search trees.
18 / 36
What will you learn in this class?
1 Growth Functions
2 Solving
Recursions
3 Probabilistic
Analysis
4 Sorting
5 Median and
Order Statistics
6 Review of Basic
Data Structures
7 Advanced Data
Structures
8 Advanced
Techniques
Advanced Data Structures
B-Trees.
Fibonacci Heaps.
Data Structures for Disjoint
Sets.
18 / 36
What will you learn in this class?
1 Growth Functions
2 Solving
Recursions
3 Probabilistic
Analysis
4 Sorting
5 Median and
Order Statistics
6 Review of Basic
Data Structures
7 Advanced Data
Structures
8 Advanced
Techniques
Advanced Techniques
Dynamic Programming.
Greedy Algorithms.
Amortized Analysis.
Introduction to Analytic
Combinatronic
18 / 36
What will you learn in this class?
1 Graph Algorithms
2 Selected Topics
3 NP-Completeness
4 Approximation
Algorithm
Graph Algorithms
Elementary Graph Algorithms.
Minimum Spanning Trees.
Strongly Connected
components.
Single-Source Shortest Paths.
All-Pairs Shortest Paths.
19 / 36
What will you learn in this class?
1 Graph Algorithms
2 Selected Topics
3 NP-Completeness
4 Approximation
Algorithm
Applications
Multithreaded Algorithms.
String Matching.
Computational Geometry
19 / 36
What will you learn in this class?
1 Graph Algorithms
2 Selected Topics
3 NP-Completeness
4 Approximation
Algorithm
The Hard Problem
Encodings.
Polynomial Time Verification.
Polynomial Reduction.
NP-Hard.
NP-Complete proofs.
A family of NP-Problems
19 / 36
What will you learn in this class?
1 Graph Algorithms
2 Selected Topics
3 NP-Completeness
4 Approximation
Algorithm
Dealing with NP
If almost everything is NP, What to
do?
Backtracking
Branch and Bound
Approximation Algorithms
19 / 36
Now, what we are going to look at!!!
First
Some stuff about notation!!!
Second
What abstraction of a Computer to use?
Third
A first approach to analyzing algorithms!!!
20 / 36
Now, what we are going to look at!!!
First
Some stuff about notation!!!
Second
What abstraction of a Computer to use?
Third
A first approach to analyzing algorithms!!!
20 / 36
Now, what we are going to look at!!!
First
Some stuff about notation!!!
Second
What abstraction of a Computer to use?
Third
A first approach to analyzing algorithms!!!
20 / 36
Outline
1 Motivation
What is an Algorithm?
Instance of a Problem
Kolmogorov’s Definition
2 Problems Solved By Algorithms
What Problems Are Solved By Algorithms?
3 Syllabus
Subjects for the Class
4 Some Notes in Notation
Before Anything, The Notation for Pseudo-Code
5 What abstraction of a Computer to use?
The Random-Access Machine (RAM) Machine
6 Analyzing Algorithms
How Input Size affects Running Time
The First Method: Counting Number of Operations
Counting Equation For Insertion Sort
The Analysis of the Best and Worst Case Inputs
21 / 36
Please follow these simple rules
Insertion Sort(A)
1 for j ← 2 to length(A)
2 do
3 key ← A[j]
4 Insert A[j] into the sorted sequence A[1, ..., j − 1]}
5 i ← j − 1
6 while i > 0 and A[i] > key
7 do
8 A[i + 1] ← A[i]
9 i ← i − 1
10 A[i + 1] ← key
Rule
Always put the name of the algorithm at the top.
Together with the input.
22 / 36
Please follow these simple rules
Insertion Sort(A)
1 for j ← 2 to length(A)
2 do
3 key ← A[j]
4 Insert A[j] into the sorted sequence A[1, ..., j − 1]}
5 i ← j − 1
6 while i > 0 and A[i] > key
7 do
8 A[i + 1] ← A[i]
9 i ← i − 1
10 A[i + 1] ← key
Rule
Always initialize all the variables.
The a ← b means that the value b is passed to a. You also can use
"=."
22 / 36
Please follow these simple rules
Insertion Sort(A)
1 for j ← 2 to length(A)
2 do
3 key ← A[j]
4 Insert A[j] into the sorted sequence A[1, ..., j − 1]}
5 i ← j − 1
6 while i > 0 and A[i] > key
7 do
8 A[i + 1] ← A[i]
9 i ← i − 1
10 A[i + 1] ← key
Rule
Use identation to preserve the block structure avoiding clutter
22 / 36
Please follow these simple rules
Insertion Sort(A)
1 for j ← 2 to length(A)
2 do
3 key ← A[j]
4 Insert A[j] into the sorted sequence A[1, ..., j − 1]}
5 i ← j − 1
6 while i > 0 and A[i] > key
7 do
8 A[i + 1] ← A[i]
9 i ← i − 1
10 A[i + 1] ← key
Rule
It corresponds to comments. You can also use "//"
22 / 36
Outline
1 Motivation
What is an Algorithm?
Instance of a Problem
Kolmogorov’s Definition
2 Problems Solved By Algorithms
What Problems Are Solved By Algorithms?
3 Syllabus
Subjects for the Class
4 Some Notes in Notation
Before Anything, The Notation for Pseudo-Code
5 What abstraction of a Computer to use?
The Random-Access Machine (RAM) Machine
6 Analyzing Algorithms
How Input Size affects Running Time
The First Method: Counting Number of Operations
Counting Equation For Insertion Sort
The Analysis of the Best and Worst Case Inputs
23 / 36
The Random-Access Machine
Definition
A Random Access Machine (RAM) is an abstract computational-machine
model identical to a multiple-register counter machine with the addition of
indirect addressing.
Instructions
Instructions are executed one after another.
It contains arithmetic instructions found in low level languages.
It has control instructions: Conditional and unconditional branches,
return and call functions.
It is able to do data movement: load, store, copy.
It posses data types: integer and floating point.
Memory Model
A single block of memory is assumed.
24 / 36
The Random-Access Machine
Definition
A Random Access Machine (RAM) is an abstract computational-machine
model identical to a multiple-register counter machine with the addition of
indirect addressing.
Instructions
Instructions are executed one after another.
It contains arithmetic instructions found in low level languages.
It has control instructions: Conditional and unconditional branches,
return and call functions.
It is able to do data movement: load, store, copy.
It posses data types: integer and floating point.
Memory Model
A single block of memory is assumed.
24 / 36
The Random-Access Machine
Definition
A Random Access Machine (RAM) is an abstract computational-machine
model identical to a multiple-register counter machine with the addition of
indirect addressing.
Instructions
Instructions are executed one after another.
It contains arithmetic instructions found in low level languages.
It has control instructions: Conditional and unconditional branches,
return and call functions.
It is able to do data movement: load, store, copy.
It posses data types: integer and floating point.
Memory Model
A single block of memory is assumed.
24 / 36
The Random-Access Machine
Definition
A Random Access Machine (RAM) is an abstract computational-machine
model identical to a multiple-register counter machine with the addition of
indirect addressing.
Instructions
Instructions are executed one after another.
It contains arithmetic instructions found in low level languages.
It has control instructions: Conditional and unconditional branches,
return and call functions.
It is able to do data movement: load, store, copy.
It posses data types: integer and floating point.
Memory Model
A single block of memory is assumed.
24 / 36
The Random-Access Machine
Definition
A Random Access Machine (RAM) is an abstract computational-machine
model identical to a multiple-register counter machine with the addition of
indirect addressing.
Instructions
Instructions are executed one after another.
It contains arithmetic instructions found in low level languages.
It has control instructions: Conditional and unconditional branches,
return and call functions.
It is able to do data movement: load, store, copy.
It posses data types: integer and floating point.
Memory Model
A single block of memory is assumed.
24 / 36
The Random-Access Machine
Definition
A Random Access Machine (RAM) is an abstract computational-machine
model identical to a multiple-register counter machine with the addition of
indirect addressing.
Instructions
Instructions are executed one after another.
It contains arithmetic instructions found in low level languages.
It has control instructions: Conditional and unconditional branches,
return and call functions.
It is able to do data movement: load, store, copy.
It posses data types: integer and floating point.
Memory Model
A single block of memory is assumed.
24 / 36
The Random-Access Machine
Definition
A Random Access Machine (RAM) is an abstract computational-machine
model identical to a multiple-register counter machine with the addition of
indirect addressing.
Instructions
Instructions are executed one after another.
It contains arithmetic instructions found in low level languages.
It has control instructions: Conditional and unconditional branches,
return and call functions.
It is able to do data movement: load, store, copy.
It posses data types: integer and floating point.
Memory Model
A single block of memory is assumed.
24 / 36
RAM Model
We have that
Control System
Memory With Random Access
Infinite
Register 1
Register 2
Register N
Inst
Inst
Inst
Inst
Inst
Inst
Inst
Inst
25 / 36
Although there are other equivalent models
Von Neumann architecture scheme
Arithmetic
Logic
Unit
Control
Unit
Memory
Input Output
Accumulator
26 / 36
Outline
1 Motivation
What is an Algorithm?
Instance of a Problem
Kolmogorov’s Definition
2 Problems Solved By Algorithms
What Problems Are Solved By Algorithms?
3 Syllabus
Subjects for the Class
4 Some Notes in Notation
Before Anything, The Notation for Pseudo-Code
5 What abstraction of a Computer to use?
The Random-Access Machine (RAM) Machine
6 Analyzing Algorithms
How Input Size affects Running Time
The First Method: Counting Number of Operations
Counting Equation For Insertion Sort
The Analysis of the Best and Worst Case Inputs
27 / 36
Input Size and Running Time
Definition
The Input Size depends on the type of problem. We will indicate which
input size is used per problem.
Definition
The Running Time of an algorithm is the number of of primitives
operations or steps executed. For now, we will assume that each line in an
algorithm takes ci a constant time.
28 / 36
Input Size and Running Time
Definition
The Input Size depends on the type of problem. We will indicate which
input size is used per problem.
Definition
The Running Time of an algorithm is the number of of primitives
operations or steps executed. For now, we will assume that each line in an
algorithm takes ci a constant time.
28 / 36
Even Babbage cared about how many turns of the crank
were necessary!!!
Look at the crank!!!
29 / 36
Outline
1 Motivation
What is an Algorithm?
Instance of a Problem
Kolmogorov’s Definition
2 Problems Solved By Algorithms
What Problems Are Solved By Algorithms?
3 Syllabus
Subjects for the Class
4 Some Notes in Notation
Before Anything, The Notation for Pseudo-Code
5 What abstraction of a Computer to use?
The Random-Access Machine (RAM) Machine
6 Analyzing Algorithms
How Input Size affects Running Time
The First Method: Counting Number of Operations
Counting Equation For Insertion Sort
The Analysis of the Best and Worst Case Inputs
30 / 36
Counting the Operations
Insertion Sort(A) length(A):=N
1 for j← 2 to length(A)
2 do
3 key ← A[j]
4 Insert A[j] into the sorted sequence A[1, ..., j − 1]}
5 i ← j − 1
6 while i > 0 and A[i] > key
7 do
8 A[i + 1] ← A[i]
9 i ← i − 1
10 A[i + 1] ← key
Count Value
c1N
31 / 36
Counting the Operations
Insertion Sort(A) length(A):=N
1 for j← 2 to length(A)
2 do
3 key ← A[j]
4 Insert A[j] into the sorted sequence A[1, ..., j − 1]}
5 i ← j − 1
6 while i > 0 and A[i] > key
7 do
8 A[i + 1] ← A[i]
9 i ← i − 1
10 A[i + 1] ← key
Count Value
c2(N − 1)
31 / 36
Counting the Operations
Insertion Sort(A) length(A):=N
1 for j← 2 to length(A)
2 do
3 key ← A[j]
4 Insert A[j] into the sorted sequence A[1, ..., j − 1]}
5 i ← j − 1
6 while i > 0 and A[i] > key
7 do
8 A[i + 1] ← A[i]
9 i ← i − 1
10 A[i + 1] ← key
Count Value
c3(N − 1)
31 / 36
Counting the Operations
Insertion Sort(A) length(A):=N
1 for j← 2 to length(A)
2 do
3 key ← A[j]
4 Insert A[j] into the sorted sequence A[1, ..., j − 1]}
5 i ← j − 1
6 while i > 0 and A[i] > key
7 do
8 A[i + 1] ← A[i]
9 i ← i − 1
10 A[i + 1] ← key
Count Value
c4
N
j=2 j
31 / 36
Counting the Operations
Insertion Sort(A) length(A):=N
1 for j← 2 to length(A)
2 do
3 key ← A[j]
4 Insert A[j] into the sorted sequence A[1, ..., j − 1]}
5 i ← j − 1
6 while i > 0 and A[i] > key
7 do
8 A[i + 1] ← A[i]
9 i ← i − 1
10 A[i + 1] ← key
Count Value
c5
N
j=2(j − 1)
31 / 36
Counting the Operations
Insertion Sort(A) length(A):=N
1 for j← 2 to length(A)
2 do
3 key ← A[j]
4 Insert A[j] into the sorted sequence A[1, ..., j − 1]}
5 i ← j − 1
6 while i > 0 and A[i] > key
7 do
8 A[i + 1] ← A[i]
9 i ← i − 1
10 A[i + 1] ← key
Count Value
c6
N
j=2(j − 1)
31 / 36
Counting the Operations
Insertion Sort(A) length(A):=N
1 for j← 2 to length(A)
2 do
3 key ← A[j]
4 Insert A[j] into the sorted sequence A[1, ..., j − 1]}
5 i ← j − 1
6 while i > 0 and A[i] > key
7 do
8 A[i + 1] ← A[i]
9 i ← i − 1
10 A[i + 1] ← key
Count Value
c7(N − 1)
31 / 36
Outline
1 Motivation
What is an Algorithm?
Instance of a Problem
Kolmogorov’s Definition
2 Problems Solved By Algorithms
What Problems Are Solved By Algorithms?
3 Syllabus
Subjects for the Class
4 Some Notes in Notation
Before Anything, The Notation for Pseudo-Code
5 What abstraction of a Computer to use?
The Random-Access Machine (RAM) Machine
6 Analyzing Algorithms
How Input Size affects Running Time
The First Method: Counting Number of Operations
Counting Equation For Insertion Sort
The Analysis of the Best and Worst Case Inputs
32 / 36
Building a function for Analyzing Complexities
What can we do with all these quantities?
Sum them all to get a step count that can be related to computational
complexities!!!
Counting Equation
T(N) = c1N + c2(N − 1) + c3(N − 1) + c4
N(N+1)
2 − 1 + ...
c5
N(N−1)
2 + c6
N(N−1)
2 + c7 (N − 1)
This can be reduced to something like...
T(N) = aN2 + bN + c
33 / 36
Building a function for Analyzing Complexities
What can we do with all these quantities?
Sum them all to get a step count that can be related to computational
complexities!!!
Counting Equation
T(N) = c1N + c2(N − 1) + c3(N − 1) + c4
N(N+1)
2 − 1 + ...
c5
N(N−1)
2 + c6
N(N−1)
2 + c7 (N − 1)
This can be reduced to something like...
T(N) = aN2 + bN + c
33 / 36
Building a function for Analyzing Complexities
What can we do with all these quantities?
Sum them all to get a step count that can be related to computational
complexities!!!
Counting Equation
T(N) = c1N + c2(N − 1) + c3(N − 1) + c4
N(N+1)
2 − 1 + ...
c5
N(N−1)
2 + c6
N(N−1)
2 + c7 (N − 1)
This can be reduced to something like...
T(N) = aN2 + bN + c
33 / 36
Building a function for Analyzing Complexities
What can we do with all these quantities?
Sum them all to get a step count that can be related to computational
complexities!!!
Counting Equation
T(N) = c1N + c2(N − 1) + c3(N − 1) + c4
N(N+1)
2 − 1 + ...
c5
N(N−1)
2 + c6
N(N−1)
2 + c7 (N − 1)
This can be reduced to something like...
T(N) = aN2 + bN + c
33 / 36
Outline
1 Motivation
What is an Algorithm?
Instance of a Problem
Kolmogorov’s Definition
2 Problems Solved By Algorithms
What Problems Are Solved By Algorithms?
3 Syllabus
Subjects for the Class
4 Some Notes in Notation
Before Anything, The Notation for Pseudo-Code
5 What abstraction of a Computer to use?
The Random-Access Machine (RAM) Machine
6 Analyzing Algorithms
How Input Size affects Running Time
The First Method: Counting Number of Operations
Counting Equation For Insertion Sort
The Analysis of the Best and Worst Case Inputs
34 / 36
The Worst and The Average
1 The Worst Case
2 The Average
Case
Worst Sequence
Upper bound on the running
time of an algorithm.
In case of insertion sort, it will
be the permutation:
N, N − 1, N − 2, ..., 3, 2, 1
35 / 36
The Worst and The Average
1 The Worst Case
2 The Average
Case
Average Sequence
In the case of insertion sort,
when half of the elements of
A[1, 2, ..., j − 1] are less than
A[j] and half are greater.
Then, there is only the need to
check half of the elements i.e.
j
2.
35 / 36
WHY TO LOOK FOR EFFICIENT ALGORITHMS?
Example
1 Insertion Sort
2 Merge Sort
3 Constraints
for the
example
4 Final Result
Example
T(N) = c1N2
36 / 36
WHY TO LOOK FOR EFFICIENT ALGORITHMS?
Example
1 Insertion Sort
2 Merge Sort
3 Constraints
for the
example
4 Final Result
Example
T(N) = c2N log2 N
36 / 36
WHY TO LOOK FOR EFFICIENT ALGORITHMS?
Example
1 Insertion Sort
2 Merge Sort
3 Constraints
for the
example
4 Final Result
Example
Assume, we have 106 numbers to
sort, c1 = 2 for a supercomputer
and c2 = 50 for a PC.
The supercomputer can do 1010
instructions per second.
The PC can do 107 instructions per
second.
36 / 36
WHY TO LOOK FOR EFFICIENT ALGORITHMS?
Example
1 Insertion Sort
2 Merge Sort
3 Constraints
for the
example
4 Final Result
Example
Insertion Sort in the Supercomputer
2(106)2 ins
1010 ins/sec
= 200sec
Merge Sort in the Humble PC
2(106) log(106) ins
107 ins/sec
= 3.9sec
36 / 36

More Related Content

What's hot

CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMS
Kathirvel Ayyaswamy
 
Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}
FellowBuddy.com
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
Dr. C.V. Suresh Babu
 
1.1. the central concepts of automata theory
1.1. the central concepts of automata theory1.1. the central concepts of automata theory
1.1. the central concepts of automata theory
Sampath Kumar S
 
Machine Learning and Data Mining
Machine Learning and Data MiningMachine Learning and Data Mining
Simulation-Run-Statistics
Simulation-Run-StatisticsSimulation-Run-Statistics
Simulation-Run-Statisticssadiksha kafle
 
Distributed concurrency control
Distributed concurrency controlDistributed concurrency control
Distributed concurrency control
Binte fatima
 
search strategies in artificial intelligence
search strategies in artificial intelligencesearch strategies in artificial intelligence
search strategies in artificial intelligence
Hanif Ullah (Gold Medalist)
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
shashidharPapishetty
 
Parallel processing (simd and mimd)
Parallel processing (simd and mimd)Parallel processing (simd and mimd)
Parallel processing (simd and mimd)
Bhavik Vashi
 
Hill climbing algorithm
Hill climbing algorithmHill climbing algorithm
Hill climbing algorithm
Dr. C.V. Suresh Babu
 
Heuristc Search Techniques
Heuristc Search TechniquesHeuristc Search Techniques
Heuristc Search Techniques
Jismy .K.Jose
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
Rajendran
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm Analysis
Mary Margarat
 
Forms of learning in ai
Forms of learning in aiForms of learning in ai
Forms of learning in ai
Robert Antony
 
Local search algorithm
Local search algorithmLocal search algorithm
Local search algorithm
Megha Sharma
 
Scheduling
SchedulingScheduling
Particle filter
Particle filterParticle filter
Particle filter
Mohammad Reza Jabbari
 

What's hot (20)

CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMS
 
Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
1.1. the central concepts of automata theory
1.1. the central concepts of automata theory1.1. the central concepts of automata theory
1.1. the central concepts of automata theory
 
Machine Learning and Data Mining
Machine Learning and Data MiningMachine Learning and Data Mining
Machine Learning and Data Mining
 
Simulation-Run-Statistics
Simulation-Run-StatisticsSimulation-Run-Statistics
Simulation-Run-Statistics
 
Distributed concurrency control
Distributed concurrency controlDistributed concurrency control
Distributed concurrency control
 
search strategies in artificial intelligence
search strategies in artificial intelligencesearch strategies in artificial intelligence
search strategies in artificial intelligence
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
 
Parallel processing (simd and mimd)
Parallel processing (simd and mimd)Parallel processing (simd and mimd)
Parallel processing (simd and mimd)
 
Hill climbing algorithm
Hill climbing algorithmHill climbing algorithm
Hill climbing algorithm
 
Heuristc Search Techniques
Heuristc Search TechniquesHeuristc Search Techniques
Heuristc Search Techniques
 
Load balancing
Load balancingLoad balancing
Load balancing
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm Analysis
 
Forms of learning in ai
Forms of learning in aiForms of learning in ai
Forms of learning in ai
 
Local search algorithm
Local search algorithmLocal search algorithm
Local search algorithm
 
Scheduling
SchedulingScheduling
Scheduling
 
Particle filter
Particle filterParticle filter
Particle filter
 

Viewers also liked

Divide and conquer 1
Divide and conquer 1Divide and conquer 1
Divide and conquer 1Kumar
 
Lecture 8 dynamic programming
Lecture 8 dynamic programmingLecture 8 dynamic programming
Lecture 8 dynamic programmingOye Tu
 
01 Notes Introduction Analysis of Algorithms Notes
01 Notes Introduction Analysis of Algorithms Notes01 Notes Introduction Analysis of Algorithms Notes
01 Notes Introduction Analysis of Algorithms Notes
Andres Mendez-Vazquez
 
x1 t10 04 maximum & minimum problems (13)
x1 t10 04 maximum & minimum problems (13)x1 t10 04 maximum & minimum problems (13)
x1 t10 04 maximum & minimum problems (13)Nigel Simmons
 
Alg1 8.2 Substitution Method
Alg1 8.2 Substitution MethodAlg1 8.2 Substitution Method
Alg1 8.2 Substitution MethodJaqueline Vallejo
 
String matching Algorithm by Foysal
String matching Algorithm by FoysalString matching Algorithm by Foysal
String matching Algorithm by Foysal
Foysal Mahmud
 
Algorithm chapter 2
Algorithm chapter 2Algorithm chapter 2
Algorithm chapter 2chidabdu
 
Lecture 6-cs648 Randomized Algorithms
Lecture 6-cs648 Randomized AlgorithmsLecture 6-cs648 Randomized Algorithms
Lecture 6-cs648 Randomized AlgorithmsAnshul Yadav
 
Algorithm
AlgorithmAlgorithm
Algorithm
eShikshak
 
Randomized Algorithm
Randomized AlgorithmRandomized Algorithm
Randomized Algorithm
Kanishka Khandelwal
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms ISri Prasanna
 
Master method
Master method Master method
Master method
Rajendran
 
DESIGN AND ANALYSIS OF ALGORITHM (DAA)
DESIGN AND ANALYSIS OF ALGORITHM (DAA)DESIGN AND ANALYSIS OF ALGORITHM (DAA)
DESIGN AND ANALYSIS OF ALGORITHM (DAA)
m.kumarasamy college of engineering
 
Minimum spanning Tree
Minimum spanning TreeMinimum spanning Tree
Minimum spanning Tree
Narendra Singh Patel
 
strassen matrix multiplication algorithm
strassen matrix multiplication algorithmstrassen matrix multiplication algorithm
strassen matrix multiplication algorithm
evil eye
 
Templates
TemplatesTemplates
Templates
Nilesh Dalvi
 

Viewers also liked (20)

Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
 
Greedy
GreedyGreedy
Greedy
 
Divide and conquer 1
Divide and conquer 1Divide and conquer 1
Divide and conquer 1
 
Lecture 8 dynamic programming
Lecture 8 dynamic programmingLecture 8 dynamic programming
Lecture 8 dynamic programming
 
Knapsack Problem
Knapsack ProblemKnapsack Problem
Knapsack Problem
 
01 Notes Introduction Analysis of Algorithms Notes
01 Notes Introduction Analysis of Algorithms Notes01 Notes Introduction Analysis of Algorithms Notes
01 Notes Introduction Analysis of Algorithms Notes
 
x1 t10 04 maximum & minimum problems (13)
x1 t10 04 maximum & minimum problems (13)x1 t10 04 maximum & minimum problems (13)
x1 t10 04 maximum & minimum problems (13)
 
Alg1 8.2 Substitution Method
Alg1 8.2 Substitution MethodAlg1 8.2 Substitution Method
Alg1 8.2 Substitution Method
 
String matching Algorithm by Foysal
String matching Algorithm by FoysalString matching Algorithm by Foysal
String matching Algorithm by Foysal
 
Algorithm chapter 2
Algorithm chapter 2Algorithm chapter 2
Algorithm chapter 2
 
Lecture 6-cs648 Randomized Algorithms
Lecture 6-cs648 Randomized AlgorithmsLecture 6-cs648 Randomized Algorithms
Lecture 6-cs648 Randomized Algorithms
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
Randomized Algorithm
Randomized AlgorithmRandomized Algorithm
Randomized Algorithm
 
Analysis of Algorithm
Analysis of AlgorithmAnalysis of Algorithm
Analysis of Algorithm
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms I
 
Master method
Master method Master method
Master method
 
DESIGN AND ANALYSIS OF ALGORITHM (DAA)
DESIGN AND ANALYSIS OF ALGORITHM (DAA)DESIGN AND ANALYSIS OF ALGORITHM (DAA)
DESIGN AND ANALYSIS OF ALGORITHM (DAA)
 
Minimum spanning Tree
Minimum spanning TreeMinimum spanning Tree
Minimum spanning Tree
 
strassen matrix multiplication algorithm
strassen matrix multiplication algorithmstrassen matrix multiplication algorithm
strassen matrix multiplication algorithm
 
Templates
TemplatesTemplates
Templates
 

Similar to 01 Analysis of Algorithms: Introduction

c_algo_flowchart.pdf
c_algo_flowchart.pdfc_algo_flowchart.pdf
c_algo_flowchart.pdf
simmis5
 
2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf
ishan743441
 
ALGO.ppt
ALGO.pptALGO.ppt
ALGO.ppt
PidoonEsm
 
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and AlgorithmsCP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
Sheba41
 
Building blocks of Algblocks of Alg.pptx
Building blocks of Algblocks of Alg.pptxBuilding blocks of Algblocks of Alg.pptx
Building blocks of Algblocks of Alg.pptx
NISHASOMSCS113
 
Practical 01 (detailed)
Practical 01 (detailed)Practical 01 (detailed)
Practical 01 (detailed)
Muhammadalizardari
 
Process Synchronization -1.ppt
Process Synchronization -1.pptProcess Synchronization -1.ppt
Process Synchronization -1.ppt
jayverma27
 
Week1 programming challenges
Week1 programming challengesWeek1 programming challenges
Week1 programming challenges
Dhanu Srikar
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
Sachin Goyani
 
Ch7 OS
Ch7 OSCh7 OS
Ch7 OSC.U
 
Unit 2 algorithm
Unit   2 algorithmUnit   2 algorithm
Unit 2 algorithm
Dabbal Singh Mahara
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
MemMem25
 
19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf
GOWTHAMR721887
 
Analysis and Design of Algorithms notes
Analysis and Design of Algorithms  notesAnalysis and Design of Algorithms  notes
Analysis and Design of Algorithms notes
Prof. Dr. K. Adisesha
 
Relational Operators in C
Relational Operators in CRelational Operators in C
Relational Operators in C
Lakshmi Sarvani Videla
 
CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of Algorithms
Krishnan MuthuManickam
 
INTRODUCTION TO ALGORITHM in MATHEMATICAL PROBLEM SOLVING
INTRODUCTION TO ALGORITHM in MATHEMATICAL PROBLEM SOLVINGINTRODUCTION TO ALGORITHM in MATHEMATICAL PROBLEM SOLVING
INTRODUCTION TO ALGORITHM in MATHEMATICAL PROBLEM SOLVING
SwastiSwagat
 
Flowcharting week 5 2019 2020
Flowcharting week 5  2019  2020Flowcharting week 5  2019  2020
Flowcharting week 5 2019 2020
Osama Ghandour Geris
 
3 analysis.gtm
3 analysis.gtm3 analysis.gtm
3 analysis.gtm
Natarajan Angappan
 

Similar to 01 Analysis of Algorithms: Introduction (20)

c_algo_flowchart.pdf
c_algo_flowchart.pdfc_algo_flowchart.pdf
c_algo_flowchart.pdf
 
Lect 3-4 Zaheer Abbas
Lect 3-4 Zaheer AbbasLect 3-4 Zaheer Abbas
Lect 3-4 Zaheer Abbas
 
2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf
 
ALGO.ppt
ALGO.pptALGO.ppt
ALGO.ppt
 
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and AlgorithmsCP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
 
Building blocks of Algblocks of Alg.pptx
Building blocks of Algblocks of Alg.pptxBuilding blocks of Algblocks of Alg.pptx
Building blocks of Algblocks of Alg.pptx
 
Practical 01 (detailed)
Practical 01 (detailed)Practical 01 (detailed)
Practical 01 (detailed)
 
Process Synchronization -1.ppt
Process Synchronization -1.pptProcess Synchronization -1.ppt
Process Synchronization -1.ppt
 
Week1 programming challenges
Week1 programming challengesWeek1 programming challenges
Week1 programming challenges
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
Ch7 OS
Ch7 OSCh7 OS
Ch7 OS
 
Unit 2 algorithm
Unit   2 algorithmUnit   2 algorithm
Unit 2 algorithm
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
 
19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf
 
Analysis and Design of Algorithms notes
Analysis and Design of Algorithms  notesAnalysis and Design of Algorithms  notes
Analysis and Design of Algorithms notes
 
Relational Operators in C
Relational Operators in CRelational Operators in C
Relational Operators in C
 
CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of Algorithms
 
INTRODUCTION TO ALGORITHM in MATHEMATICAL PROBLEM SOLVING
INTRODUCTION TO ALGORITHM in MATHEMATICAL PROBLEM SOLVINGINTRODUCTION TO ALGORITHM in MATHEMATICAL PROBLEM SOLVING
INTRODUCTION TO ALGORITHM in MATHEMATICAL PROBLEM SOLVING
 
Flowcharting week 5 2019 2020
Flowcharting week 5  2019  2020Flowcharting week 5  2019  2020
Flowcharting week 5 2019 2020
 
3 analysis.gtm
3 analysis.gtm3 analysis.gtm
3 analysis.gtm
 

More from Andres Mendez-Vazquez

2.03 bayesian estimation
2.03 bayesian estimation2.03 bayesian estimation
2.03 bayesian estimation
Andres Mendez-Vazquez
 
05 linear transformations
05 linear transformations05 linear transformations
05 linear transformations
Andres Mendez-Vazquez
 
01.04 orthonormal basis_eigen_vectors
01.04 orthonormal basis_eigen_vectors01.04 orthonormal basis_eigen_vectors
01.04 orthonormal basis_eigen_vectors
Andres Mendez-Vazquez
 
01.03 squared matrices_and_other_issues
01.03 squared matrices_and_other_issues01.03 squared matrices_and_other_issues
01.03 squared matrices_and_other_issues
Andres Mendez-Vazquez
 
01.02 linear equations
01.02 linear equations01.02 linear equations
01.02 linear equations
Andres Mendez-Vazquez
 
01.01 vector spaces
01.01 vector spaces01.01 vector spaces
01.01 vector spaces
Andres Mendez-Vazquez
 
06 recurrent neural_networks
06 recurrent neural_networks06 recurrent neural_networks
06 recurrent neural_networks
Andres Mendez-Vazquez
 
05 backpropagation automatic_differentiation
05 backpropagation automatic_differentiation05 backpropagation automatic_differentiation
05 backpropagation automatic_differentiation
Andres Mendez-Vazquez
 
Zetta global
Zetta globalZetta global
Zetta global
Andres Mendez-Vazquez
 
01 Introduction to Neural Networks and Deep Learning
01 Introduction to Neural Networks and Deep Learning01 Introduction to Neural Networks and Deep Learning
01 Introduction to Neural Networks and Deep Learning
Andres Mendez-Vazquez
 
25 introduction reinforcement_learning
25 introduction reinforcement_learning25 introduction reinforcement_learning
25 introduction reinforcement_learning
Andres Mendez-Vazquez
 
Neural Networks and Deep Learning Syllabus
Neural Networks and Deep Learning SyllabusNeural Networks and Deep Learning Syllabus
Neural Networks and Deep Learning Syllabus
Andres Mendez-Vazquez
 
Introduction to artificial_intelligence_syllabus
Introduction to artificial_intelligence_syllabusIntroduction to artificial_intelligence_syllabus
Introduction to artificial_intelligence_syllabus
Andres Mendez-Vazquez
 
Ideas 09 22_2018
Ideas 09 22_2018Ideas 09 22_2018
Ideas 09 22_2018
Andres Mendez-Vazquez
 
Ideas about a Bachelor in Machine Learning/Data Sciences
Ideas about a Bachelor in Machine Learning/Data SciencesIdeas about a Bachelor in Machine Learning/Data Sciences
Ideas about a Bachelor in Machine Learning/Data Sciences
Andres Mendez-Vazquez
 
Analysis of Algorithms Syllabus
Analysis of Algorithms  SyllabusAnalysis of Algorithms  Syllabus
Analysis of Algorithms Syllabus
Andres Mendez-Vazquez
 
20 k-means, k-center, k-meoids and variations
20 k-means, k-center, k-meoids and variations20 k-means, k-center, k-meoids and variations
20 k-means, k-center, k-meoids and variations
Andres Mendez-Vazquez
 
18.1 combining models
18.1 combining models18.1 combining models
18.1 combining models
Andres Mendez-Vazquez
 
17 vapnik chervonenkis dimension
17 vapnik chervonenkis dimension17 vapnik chervonenkis dimension
17 vapnik chervonenkis dimension
Andres Mendez-Vazquez
 
A basic introduction to learning
A basic introduction to learningA basic introduction to learning
A basic introduction to learning
Andres Mendez-Vazquez
 

More from Andres Mendez-Vazquez (20)

2.03 bayesian estimation
2.03 bayesian estimation2.03 bayesian estimation
2.03 bayesian estimation
 
05 linear transformations
05 linear transformations05 linear transformations
05 linear transformations
 
01.04 orthonormal basis_eigen_vectors
01.04 orthonormal basis_eigen_vectors01.04 orthonormal basis_eigen_vectors
01.04 orthonormal basis_eigen_vectors
 
01.03 squared matrices_and_other_issues
01.03 squared matrices_and_other_issues01.03 squared matrices_and_other_issues
01.03 squared matrices_and_other_issues
 
01.02 linear equations
01.02 linear equations01.02 linear equations
01.02 linear equations
 
01.01 vector spaces
01.01 vector spaces01.01 vector spaces
01.01 vector spaces
 
06 recurrent neural_networks
06 recurrent neural_networks06 recurrent neural_networks
06 recurrent neural_networks
 
05 backpropagation automatic_differentiation
05 backpropagation automatic_differentiation05 backpropagation automatic_differentiation
05 backpropagation automatic_differentiation
 
Zetta global
Zetta globalZetta global
Zetta global
 
01 Introduction to Neural Networks and Deep Learning
01 Introduction to Neural Networks and Deep Learning01 Introduction to Neural Networks and Deep Learning
01 Introduction to Neural Networks and Deep Learning
 
25 introduction reinforcement_learning
25 introduction reinforcement_learning25 introduction reinforcement_learning
25 introduction reinforcement_learning
 
Neural Networks and Deep Learning Syllabus
Neural Networks and Deep Learning SyllabusNeural Networks and Deep Learning Syllabus
Neural Networks and Deep Learning Syllabus
 
Introduction to artificial_intelligence_syllabus
Introduction to artificial_intelligence_syllabusIntroduction to artificial_intelligence_syllabus
Introduction to artificial_intelligence_syllabus
 
Ideas 09 22_2018
Ideas 09 22_2018Ideas 09 22_2018
Ideas 09 22_2018
 
Ideas about a Bachelor in Machine Learning/Data Sciences
Ideas about a Bachelor in Machine Learning/Data SciencesIdeas about a Bachelor in Machine Learning/Data Sciences
Ideas about a Bachelor in Machine Learning/Data Sciences
 
Analysis of Algorithms Syllabus
Analysis of Algorithms  SyllabusAnalysis of Algorithms  Syllabus
Analysis of Algorithms Syllabus
 
20 k-means, k-center, k-meoids and variations
20 k-means, k-center, k-meoids and variations20 k-means, k-center, k-meoids and variations
20 k-means, k-center, k-meoids and variations
 
18.1 combining models
18.1 combining models18.1 combining models
18.1 combining models
 
17 vapnik chervonenkis dimension
17 vapnik chervonenkis dimension17 vapnik chervonenkis dimension
17 vapnik chervonenkis dimension
 
A basic introduction to learning
A basic introduction to learningA basic introduction to learning
A basic introduction to learning
 

Recently uploaded

ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 

Recently uploaded (20)

ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 

01 Analysis of Algorithms: Introduction

  • 1. Analysis of Algorithms Introduction Andres Mendez-Vazquez September 27, 2015 1 / 36
  • 2. Outline 1 Motivation What is an Algorithm? Instance of a Problem Kolmogorov’s Definition 2 Problems Solved By Algorithms What Problems Are Solved By Algorithms? 3 Syllabus Subjects for the Class 4 Some Notes in Notation Before Anything, The Notation for Pseudo-Code 5 What abstraction of a Computer to use? The Random-Access Machine (RAM) Machine 6 Analyzing Algorithms How Input Size affects Running Time The First Method: Counting Number of Operations Counting Equation For Insertion Sort The Analysis of the Best and Worst Case Inputs 2 / 36
  • 3. Outline 1 Motivation What is an Algorithm? Instance of a Problem Kolmogorov’s Definition 2 Problems Solved By Algorithms What Problems Are Solved By Algorithms? 3 Syllabus Subjects for the Class 4 Some Notes in Notation Before Anything, The Notation for Pseudo-Code 5 What abstraction of a Computer to use? The Random-Access Machine (RAM) Machine 6 Analyzing Algorithms How Input Size affects Running Time The First Method: Counting Number of Operations Counting Equation For Insertion Sort The Analysis of the Best and Worst Case Inputs 3 / 36
  • 4. Introduction Informal definition Informally, an algorithm is any well defined computational procedure that It takes some value, or set of values, as input. Then, it produces some value, or set of values, as output. Examples 4 / 36
  • 5. Introduction Informal definition Informally, an algorithm is any well defined computational procedure that It takes some value, or set of values, as input. Then, it produces some value, or set of values, as output. Examples 4 / 36
  • 6. Introduction Informal definition Informally, an algorithm is any well defined computational procedure that It takes some value, or set of values, as input. Then, it produces some value, or set of values, as output. Examples 4 / 36
  • 7. Introduction Informal definition Informally, an algorithm is any well defined computational procedure that It takes some value, or set of values, as input. Then, it produces some value, or set of values, as output. Examples ALGORITHMINPUT Cluster 1 (7) OUTPUT 4 / 36
  • 8. Example Sorting Problem Input: A sequence of N numbers a1, a2, ..., aN Output: A reordering of the input sequence a(1), a(2), ..., a(N) Actually We are dealing with instances of a problem. 5 / 36
  • 9. Example Sorting Problem Input: A sequence of N numbers a1, a2, ..., aN Output: A reordering of the input sequence a(1), a(2), ..., a(N) Actually We are dealing with instances of a problem. 5 / 36
  • 10. Outline 1 Motivation What is an Algorithm? Instance of a Problem Kolmogorov’s Definition 2 Problems Solved By Algorithms What Problems Are Solved By Algorithms? 3 Syllabus Subjects for the Class 4 Some Notes in Notation Before Anything, The Notation for Pseudo-Code 5 What abstraction of a Computer to use? The Random-Access Machine (RAM) Machine 6 Analyzing Algorithms How Input Size affects Running Time The First Method: Counting Number of Operations Counting Equation For Insertion Sort The Analysis of the Best and Worst Case Inputs 6 / 36
  • 11. Instance of a Problem Instance of the problem For example, we have 9, 8, 5, 6, 7, 4, 3, 2, 1 Then, we finish with 1, 2, 3, 4, 5, 6, 7, 8, 9 7 / 36
  • 12. Although Instances are Important Nevertheless The way we use those instances is way more important For example Look at Recursive Fibonacci!!! 8 / 36
  • 13. Although Instances are Important Nevertheless The way we use those instances is way more important For example Look at Recursive Fibonacci!!! 8 / 36
  • 14. Example: Fibonacci Fibonacci rule Fn =    Fn−1 + Fn−2 if n > 1 1 if n = 1 0 if n = 0 Time Complexity 1 Naive version using directly the recursion - exponential time. 2 A more elegant version - linear time. 9 / 36
  • 15. Example: Fibonacci Fibonacci rule Fn =    Fn−1 + Fn−2 if n > 1 1 if n = 1 0 if n = 0 Time Complexity 1 Naive version using directly the recursion - exponential time. 2 A more elegant version - linear time. 9 / 36
  • 16. Outline 1 Motivation What is an Algorithm? Instance of a Problem Kolmogorov’s Definition 2 Problems Solved By Algorithms What Problems Are Solved By Algorithms? 3 Syllabus Subjects for the Class 4 Some Notes in Notation Before Anything, The Notation for Pseudo-Code 5 What abstraction of a Computer to use? The Random-Access Machine (RAM) Machine 6 Analyzing Algorithms How Input Size affects Running Time The First Method: Counting Number of Operations Counting Equation For Insertion Sort The Analysis of the Best and Worst Case Inputs 10 / 36
  • 17. Kolmogorov’s Definition A bound for each sub-step An algorithmic process splits into steps whose complexity is bounded in advance i.e., the bound is independent of the input and the current state of the computation. Transformations done at each step Each step consists of a direct and immediate transformation of the current state. This transformation applies only to the active part of the state and does not alter the remainder of the state. Size of the steps The size of the active part is bounded in advance. Ending the Process The process runs until either the next step is impossible or a signal says the solution has been reached. 11 / 36
  • 18. Kolmogorov’s Definition A bound for each sub-step An algorithmic process splits into steps whose complexity is bounded in advance i.e., the bound is independent of the input and the current state of the computation. Transformations done at each step Each step consists of a direct and immediate transformation of the current state. This transformation applies only to the active part of the state and does not alter the remainder of the state. Size of the steps The size of the active part is bounded in advance. Ending the Process The process runs until either the next step is impossible or a signal says the solution has been reached. 11 / 36
  • 19. Kolmogorov’s Definition A bound for each sub-step An algorithmic process splits into steps whose complexity is bounded in advance i.e., the bound is independent of the input and the current state of the computation. Transformations done at each step Each step consists of a direct and immediate transformation of the current state. This transformation applies only to the active part of the state and does not alter the remainder of the state. Size of the steps The size of the active part is bounded in advance. Ending the Process The process runs until either the next step is impossible or a signal says the solution has been reached. 11 / 36
  • 20. Kolmogorov’s Definition A bound for each sub-step An algorithmic process splits into steps whose complexity is bounded in advance i.e., the bound is independent of the input and the current state of the computation. Transformations done at each step Each step consists of a direct and immediate transformation of the current state. This transformation applies only to the active part of the state and does not alter the remainder of the state. Size of the steps The size of the active part is bounded in advance. Ending the Process The process runs until either the next step is impossible or a signal says the solution has been reached. 11 / 36
  • 21. Kolmogorov’s Definition A bound for each sub-step An algorithmic process splits into steps whose complexity is bounded in advance i.e., the bound is independent of the input and the current state of the computation. Transformations done at each step Each step consists of a direct and immediate transformation of the current state. This transformation applies only to the active part of the state and does not alter the remainder of the state. Size of the steps The size of the active part is bounded in advance. Ending the Process The process runs until either the next step is impossible or a signal says the solution has been reached. 11 / 36
  • 22. Kolmogorov’s Definition A bound for each sub-step An algorithmic process splits into steps whose complexity is bounded in advance i.e., the bound is independent of the input and the current state of the computation. Transformations done at each step Each step consists of a direct and immediate transformation of the current state. This transformation applies only to the active part of the state and does not alter the remainder of the state. Size of the steps The size of the active part is bounded in advance. Ending the Process The process runs until either the next step is impossible or a signal says the solution has been reached. 11 / 36
  • 23. BTW How do they look this machines, this algorithms? After all we like to see them!!! 12 / 36
  • 24. An Example of an Algorithm Insertion Sort Algorithm Data: Unsorted Sequence A Result: Sort Sequence A Insertion Sort(A) for j ← 2 to lenght(A) do key ← A[j]; // Insert A[j] into the sorted sequence A[1, ..., j − 1] i ← j − 1; while i > 0 and A[i] > key do A[i + 1] ← A[i]; i ← i − 1; end A[i + 1] ← key end 13 / 36
  • 25. Outline 1 Motivation What is an Algorithm? Instance of a Problem Kolmogorov’s Definition 2 Problems Solved By Algorithms What Problems Are Solved By Algorithms? 3 Syllabus Subjects for the Class 4 Some Notes in Notation Before Anything, The Notation for Pseudo-Code 5 What abstraction of a Computer to use? The Random-Access Machine (RAM) Machine 6 Analyzing Algorithms How Input Size affects Running Time The First Method: Counting Number of Operations Counting Equation For Insertion Sort The Analysis of the Best and Worst Case Inputs 14 / 36
  • 26. Problems Solved By Algorithms Single-Source Shortest Path. Solving systems of linear equations. Huffman codes Matrix Multiplication Convex hull Short Paths in Maps These algorithms allows to solve the problem of finding the shortest path in a map between two addresses. @Copyright 2010-2011 Daniel Kastl, Frédéric Junod. Mis à jour le Apr 02, 2012. 15 / 36
  • 27. Problems Solved By Algorithms Single-Source Shortest Path. Solving systems of linear equations. Huffman codes Matrix Multiplication Convex hull Inverting Matrices Normally, given the system Ax = y, we do not use the inverse A−1, but the LUP decomposition L D U R @Copyright From Wikimedia Commons, the free media repository 15 / 36
  • 28. Problems Solved By Algorithms Single-Source Shortest Path. Solving systems of linear equations. Huffman codes Matrix Multiplication Convex hull Compression Trees This method is part of the greedy methods. They are used for compression, they can achieve 20% to 90% compression. 8 17 41 24 109 5 3 2 2 2 2 6 2 3 4 7 14 3 22 1 1 2 4 7 2 1111 4 4 ' ' 'U' 'A' 'L' 'M' 'E' 'D' 'F' 'N' 'S' 'B' 'H' 'O' 'J' 'P' 'R' 'T' @Copyright From Wikimedia Commons, the free media repository 15 / 36
  • 29. Problems Solved By Algorithms Single-Source Shortest Path. Solving systems of linear equations. Huffman codes Matrix Multiplication Convex hull Fast Multiplication of Matrices In many algorithms, we want to multiply different n × n matrices A11 A12 A21 A22 B11 B12 B21 B22 C11 1 1 C12 1 1 C21 1 1 C22 1 1 1 11 1 1 1 11 1 1 -1-1 1 -1 1 -1 1 -1 1 -1 1 1 -1-1 1 1 -1 -1 1 1 -1 -1 M1 M2 M3 M4 M5 M6 M7 STRASSEN'S ALGORITHM @Copyright From Wikimedia Commons, the free media repository 15 / 36
  • 30. Problems Solved By Algorithms Single-Source Shortest Path. Solving systems of linear equations. Huffman codes Matrix Multiplication Convex hull Computational Geometry Given the points in a plane, we want to find the minimum convex hull that encloses them. p0 p1 p2 p3 @Copyright From Wikimedia Commons, the free media repository 15 / 36
  • 31. Problems Solved By Algorithms Synthetic Biology Pattern Recognition Databases Face Recognition Computational Molecular Engineering In this field the engineers and biologist try to use the basis of life to create complex molecular machines. All these machines will requiere complex algorithms @Copyright 2002-2013 SYNTHETIC COMPONENTS NETWORK University of Bristol 16 / 36
  • 32. Problems Solved By Algorithms Synthetic Biology Pattern Recognition Databases Face Recognition Machine Learning In pattern recognition, we try to find specific patterns in data. @2013Copyright Bülent Üstün, Department of Analytical Chemistry, University of Nijmegen 16 / 36
  • 33. Problems Solved By Algorithms Synthetic Biology Pattern Recognition Databases Face Recognition Partition of the Database Space A grid file or bucket grid is a point access method: Query A1 = 'x' and A2 = 6 a f k p z A2 A1 Grid Array Pointers to buckets 0 2 7 10 15 Intervals Define Search Areas A1 Bucket Accessed @Copyright Michael Unwalla: A mixed transaction cost model for coarse grained multi-column partitioning in a shared-nothing database machine 16 / 36
  • 34. Problems Solved By Algorithms Synthetic Biology Pattern Recognition Databases Face Recognition Person Identification Facial Recognition measure face landmarks to indentify different features in the face. @Copyright 2013 Wouter Alberda, Olaf Kampinga 16 / 36
  • 35. Outline 1 Motivation What is an Algorithm? Instance of a Problem Kolmogorov’s Definition 2 Problems Solved By Algorithms What Problems Are Solved By Algorithms? 3 Syllabus Subjects for the Class 4 Some Notes in Notation Before Anything, The Notation for Pseudo-Code 5 What abstraction of a Computer to use? The Random-Access Machine (RAM) Machine 6 Analyzing Algorithms How Input Size affects Running Time The First Method: Counting Number of Operations Counting Equation For Insertion Sort The Analysis of the Best and Worst Case Inputs 17 / 36
  • 36. What will you learn in this class? 1 Growth Functions 2 Solving Recursions 3 Probabilistic Analysis 4 Sorting 5 Median and Order Statistics 6 Review of Basic Data Structures 7 Advanced Data Structures 8 Advanced Techniques Basic Complexities Asymptotic Notation - Ω, O and Θ Standard notation and common functions. 18 / 36
  • 37. What will you learn in this class? 1 Growth Functions 2 Solving Recursions 3 Probabilistic Analysis 4 Sorting 5 Median and Order Statistics 6 Review of Basic Data Structures 7 Advanced Data Structures 8 Advanced Techniques For finding Complexities The substitution method. The recursive three method. The master method. 18 / 36
  • 38. What will you learn in this class? 1 Growth Functions 2 Solving Recursions 3 Probabilistic Analysis 4 Sorting 5 Median and Order Statistics 6 Review of Basic Data Structures 7 Advanced Data Structures 8 Advanced Techniques Using Probability for finding Complexities Indicator Random Variables. Randomization Algorithms. 18 / 36
  • 39. What will you learn in this class? 1 Growth Functions 2 Solving Recursions 3 Probabilistic Analysis 4 Sorting 5 Median and Order Statistics 6 Review of Basic Data Structures 7 Advanced Data Structures 8 Advanced Techniques Sorting Thecniques Heapsort. Quicksort. Sorting in linear time. 18 / 36
  • 40. What will you learn in this class? 1 Growth Functions 2 Solving Recursions 3 Probabilistic Analysis 4 Sorting 5 Median and Order Statistics 6 Review of Basic Data Structures 7 Advanced Data Structures 8 Advanced Techniques Finding Order Minimum and Maximum. Selection. Worst Case Selection. 18 / 36
  • 41. What will you learn in this class? 1 Growth Functions 2 Solving Recursions 3 Probabilistic Analysis 4 Sorting 5 Median and Order Statistics 6 Review of Basic Data Structures 7 Advanced Data Structures 8 Advanced Techniques Basic Data Structures Elementary data structures. Hash tables. Applications of Hash Tables Linear Counting Binary search trees. 18 / 36
  • 42. What will you learn in this class? 1 Growth Functions 2 Solving Recursions 3 Probabilistic Analysis 4 Sorting 5 Median and Order Statistics 6 Review of Basic Data Structures 7 Advanced Data Structures 8 Advanced Techniques Advanced Data Structures B-Trees. Fibonacci Heaps. Data Structures for Disjoint Sets. 18 / 36
  • 43. What will you learn in this class? 1 Growth Functions 2 Solving Recursions 3 Probabilistic Analysis 4 Sorting 5 Median and Order Statistics 6 Review of Basic Data Structures 7 Advanced Data Structures 8 Advanced Techniques Advanced Techniques Dynamic Programming. Greedy Algorithms. Amortized Analysis. Introduction to Analytic Combinatronic 18 / 36
  • 44. What will you learn in this class? 1 Graph Algorithms 2 Selected Topics 3 NP-Completeness 4 Approximation Algorithm Graph Algorithms Elementary Graph Algorithms. Minimum Spanning Trees. Strongly Connected components. Single-Source Shortest Paths. All-Pairs Shortest Paths. 19 / 36
  • 45. What will you learn in this class? 1 Graph Algorithms 2 Selected Topics 3 NP-Completeness 4 Approximation Algorithm Applications Multithreaded Algorithms. String Matching. Computational Geometry 19 / 36
  • 46. What will you learn in this class? 1 Graph Algorithms 2 Selected Topics 3 NP-Completeness 4 Approximation Algorithm The Hard Problem Encodings. Polynomial Time Verification. Polynomial Reduction. NP-Hard. NP-Complete proofs. A family of NP-Problems 19 / 36
  • 47. What will you learn in this class? 1 Graph Algorithms 2 Selected Topics 3 NP-Completeness 4 Approximation Algorithm Dealing with NP If almost everything is NP, What to do? Backtracking Branch and Bound Approximation Algorithms 19 / 36
  • 48. Now, what we are going to look at!!! First Some stuff about notation!!! Second What abstraction of a Computer to use? Third A first approach to analyzing algorithms!!! 20 / 36
  • 49. Now, what we are going to look at!!! First Some stuff about notation!!! Second What abstraction of a Computer to use? Third A first approach to analyzing algorithms!!! 20 / 36
  • 50. Now, what we are going to look at!!! First Some stuff about notation!!! Second What abstraction of a Computer to use? Third A first approach to analyzing algorithms!!! 20 / 36
  • 51. Outline 1 Motivation What is an Algorithm? Instance of a Problem Kolmogorov’s Definition 2 Problems Solved By Algorithms What Problems Are Solved By Algorithms? 3 Syllabus Subjects for the Class 4 Some Notes in Notation Before Anything, The Notation for Pseudo-Code 5 What abstraction of a Computer to use? The Random-Access Machine (RAM) Machine 6 Analyzing Algorithms How Input Size affects Running Time The First Method: Counting Number of Operations Counting Equation For Insertion Sort The Analysis of the Best and Worst Case Inputs 21 / 36
  • 52. Please follow these simple rules Insertion Sort(A) 1 for j ← 2 to length(A) 2 do 3 key ← A[j] 4 Insert A[j] into the sorted sequence A[1, ..., j − 1]} 5 i ← j − 1 6 while i > 0 and A[i] > key 7 do 8 A[i + 1] ← A[i] 9 i ← i − 1 10 A[i + 1] ← key Rule Always put the name of the algorithm at the top. Together with the input. 22 / 36
  • 53. Please follow these simple rules Insertion Sort(A) 1 for j ← 2 to length(A) 2 do 3 key ← A[j] 4 Insert A[j] into the sorted sequence A[1, ..., j − 1]} 5 i ← j − 1 6 while i > 0 and A[i] > key 7 do 8 A[i + 1] ← A[i] 9 i ← i − 1 10 A[i + 1] ← key Rule Always initialize all the variables. The a ← b means that the value b is passed to a. You also can use "=." 22 / 36
  • 54. Please follow these simple rules Insertion Sort(A) 1 for j ← 2 to length(A) 2 do 3 key ← A[j] 4 Insert A[j] into the sorted sequence A[1, ..., j − 1]} 5 i ← j − 1 6 while i > 0 and A[i] > key 7 do 8 A[i + 1] ← A[i] 9 i ← i − 1 10 A[i + 1] ← key Rule Use identation to preserve the block structure avoiding clutter 22 / 36
  • 55. Please follow these simple rules Insertion Sort(A) 1 for j ← 2 to length(A) 2 do 3 key ← A[j] 4 Insert A[j] into the sorted sequence A[1, ..., j − 1]} 5 i ← j − 1 6 while i > 0 and A[i] > key 7 do 8 A[i + 1] ← A[i] 9 i ← i − 1 10 A[i + 1] ← key Rule It corresponds to comments. You can also use "//" 22 / 36
  • 56. Outline 1 Motivation What is an Algorithm? Instance of a Problem Kolmogorov’s Definition 2 Problems Solved By Algorithms What Problems Are Solved By Algorithms? 3 Syllabus Subjects for the Class 4 Some Notes in Notation Before Anything, The Notation for Pseudo-Code 5 What abstraction of a Computer to use? The Random-Access Machine (RAM) Machine 6 Analyzing Algorithms How Input Size affects Running Time The First Method: Counting Number of Operations Counting Equation For Insertion Sort The Analysis of the Best and Worst Case Inputs 23 / 36
  • 57. The Random-Access Machine Definition A Random Access Machine (RAM) is an abstract computational-machine model identical to a multiple-register counter machine with the addition of indirect addressing. Instructions Instructions are executed one after another. It contains arithmetic instructions found in low level languages. It has control instructions: Conditional and unconditional branches, return and call functions. It is able to do data movement: load, store, copy. It posses data types: integer and floating point. Memory Model A single block of memory is assumed. 24 / 36
  • 58. The Random-Access Machine Definition A Random Access Machine (RAM) is an abstract computational-machine model identical to a multiple-register counter machine with the addition of indirect addressing. Instructions Instructions are executed one after another. It contains arithmetic instructions found in low level languages. It has control instructions: Conditional and unconditional branches, return and call functions. It is able to do data movement: load, store, copy. It posses data types: integer and floating point. Memory Model A single block of memory is assumed. 24 / 36
  • 59. The Random-Access Machine Definition A Random Access Machine (RAM) is an abstract computational-machine model identical to a multiple-register counter machine with the addition of indirect addressing. Instructions Instructions are executed one after another. It contains arithmetic instructions found in low level languages. It has control instructions: Conditional and unconditional branches, return and call functions. It is able to do data movement: load, store, copy. It posses data types: integer and floating point. Memory Model A single block of memory is assumed. 24 / 36
  • 60. The Random-Access Machine Definition A Random Access Machine (RAM) is an abstract computational-machine model identical to a multiple-register counter machine with the addition of indirect addressing. Instructions Instructions are executed one after another. It contains arithmetic instructions found in low level languages. It has control instructions: Conditional and unconditional branches, return and call functions. It is able to do data movement: load, store, copy. It posses data types: integer and floating point. Memory Model A single block of memory is assumed. 24 / 36
  • 61. The Random-Access Machine Definition A Random Access Machine (RAM) is an abstract computational-machine model identical to a multiple-register counter machine with the addition of indirect addressing. Instructions Instructions are executed one after another. It contains arithmetic instructions found in low level languages. It has control instructions: Conditional and unconditional branches, return and call functions. It is able to do data movement: load, store, copy. It posses data types: integer and floating point. Memory Model A single block of memory is assumed. 24 / 36
  • 62. The Random-Access Machine Definition A Random Access Machine (RAM) is an abstract computational-machine model identical to a multiple-register counter machine with the addition of indirect addressing. Instructions Instructions are executed one after another. It contains arithmetic instructions found in low level languages. It has control instructions: Conditional and unconditional branches, return and call functions. It is able to do data movement: load, store, copy. It posses data types: integer and floating point. Memory Model A single block of memory is assumed. 24 / 36
  • 63. The Random-Access Machine Definition A Random Access Machine (RAM) is an abstract computational-machine model identical to a multiple-register counter machine with the addition of indirect addressing. Instructions Instructions are executed one after another. It contains arithmetic instructions found in low level languages. It has control instructions: Conditional and unconditional branches, return and call functions. It is able to do data movement: load, store, copy. It posses data types: integer and floating point. Memory Model A single block of memory is assumed. 24 / 36
  • 64. RAM Model We have that Control System Memory With Random Access Infinite Register 1 Register 2 Register N Inst Inst Inst Inst Inst Inst Inst Inst 25 / 36
  • 65. Although there are other equivalent models Von Neumann architecture scheme Arithmetic Logic Unit Control Unit Memory Input Output Accumulator 26 / 36
  • 66. Outline 1 Motivation What is an Algorithm? Instance of a Problem Kolmogorov’s Definition 2 Problems Solved By Algorithms What Problems Are Solved By Algorithms? 3 Syllabus Subjects for the Class 4 Some Notes in Notation Before Anything, The Notation for Pseudo-Code 5 What abstraction of a Computer to use? The Random-Access Machine (RAM) Machine 6 Analyzing Algorithms How Input Size affects Running Time The First Method: Counting Number of Operations Counting Equation For Insertion Sort The Analysis of the Best and Worst Case Inputs 27 / 36
  • 67. Input Size and Running Time Definition The Input Size depends on the type of problem. We will indicate which input size is used per problem. Definition The Running Time of an algorithm is the number of of primitives operations or steps executed. For now, we will assume that each line in an algorithm takes ci a constant time. 28 / 36
  • 68. Input Size and Running Time Definition The Input Size depends on the type of problem. We will indicate which input size is used per problem. Definition The Running Time of an algorithm is the number of of primitives operations or steps executed. For now, we will assume that each line in an algorithm takes ci a constant time. 28 / 36
  • 69. Even Babbage cared about how many turns of the crank were necessary!!! Look at the crank!!! 29 / 36
  • 70. Outline 1 Motivation What is an Algorithm? Instance of a Problem Kolmogorov’s Definition 2 Problems Solved By Algorithms What Problems Are Solved By Algorithms? 3 Syllabus Subjects for the Class 4 Some Notes in Notation Before Anything, The Notation for Pseudo-Code 5 What abstraction of a Computer to use? The Random-Access Machine (RAM) Machine 6 Analyzing Algorithms How Input Size affects Running Time The First Method: Counting Number of Operations Counting Equation For Insertion Sort The Analysis of the Best and Worst Case Inputs 30 / 36
  • 71. Counting the Operations Insertion Sort(A) length(A):=N 1 for j← 2 to length(A) 2 do 3 key ← A[j] 4 Insert A[j] into the sorted sequence A[1, ..., j − 1]} 5 i ← j − 1 6 while i > 0 and A[i] > key 7 do 8 A[i + 1] ← A[i] 9 i ← i − 1 10 A[i + 1] ← key Count Value c1N 31 / 36
  • 72. Counting the Operations Insertion Sort(A) length(A):=N 1 for j← 2 to length(A) 2 do 3 key ← A[j] 4 Insert A[j] into the sorted sequence A[1, ..., j − 1]} 5 i ← j − 1 6 while i > 0 and A[i] > key 7 do 8 A[i + 1] ← A[i] 9 i ← i − 1 10 A[i + 1] ← key Count Value c2(N − 1) 31 / 36
  • 73. Counting the Operations Insertion Sort(A) length(A):=N 1 for j← 2 to length(A) 2 do 3 key ← A[j] 4 Insert A[j] into the sorted sequence A[1, ..., j − 1]} 5 i ← j − 1 6 while i > 0 and A[i] > key 7 do 8 A[i + 1] ← A[i] 9 i ← i − 1 10 A[i + 1] ← key Count Value c3(N − 1) 31 / 36
  • 74. Counting the Operations Insertion Sort(A) length(A):=N 1 for j← 2 to length(A) 2 do 3 key ← A[j] 4 Insert A[j] into the sorted sequence A[1, ..., j − 1]} 5 i ← j − 1 6 while i > 0 and A[i] > key 7 do 8 A[i + 1] ← A[i] 9 i ← i − 1 10 A[i + 1] ← key Count Value c4 N j=2 j 31 / 36
  • 75. Counting the Operations Insertion Sort(A) length(A):=N 1 for j← 2 to length(A) 2 do 3 key ← A[j] 4 Insert A[j] into the sorted sequence A[1, ..., j − 1]} 5 i ← j − 1 6 while i > 0 and A[i] > key 7 do 8 A[i + 1] ← A[i] 9 i ← i − 1 10 A[i + 1] ← key Count Value c5 N j=2(j − 1) 31 / 36
  • 76. Counting the Operations Insertion Sort(A) length(A):=N 1 for j← 2 to length(A) 2 do 3 key ← A[j] 4 Insert A[j] into the sorted sequence A[1, ..., j − 1]} 5 i ← j − 1 6 while i > 0 and A[i] > key 7 do 8 A[i + 1] ← A[i] 9 i ← i − 1 10 A[i + 1] ← key Count Value c6 N j=2(j − 1) 31 / 36
  • 77. Counting the Operations Insertion Sort(A) length(A):=N 1 for j← 2 to length(A) 2 do 3 key ← A[j] 4 Insert A[j] into the sorted sequence A[1, ..., j − 1]} 5 i ← j − 1 6 while i > 0 and A[i] > key 7 do 8 A[i + 1] ← A[i] 9 i ← i − 1 10 A[i + 1] ← key Count Value c7(N − 1) 31 / 36
  • 78. Outline 1 Motivation What is an Algorithm? Instance of a Problem Kolmogorov’s Definition 2 Problems Solved By Algorithms What Problems Are Solved By Algorithms? 3 Syllabus Subjects for the Class 4 Some Notes in Notation Before Anything, The Notation for Pseudo-Code 5 What abstraction of a Computer to use? The Random-Access Machine (RAM) Machine 6 Analyzing Algorithms How Input Size affects Running Time The First Method: Counting Number of Operations Counting Equation For Insertion Sort The Analysis of the Best and Worst Case Inputs 32 / 36
  • 79. Building a function for Analyzing Complexities What can we do with all these quantities? Sum them all to get a step count that can be related to computational complexities!!! Counting Equation T(N) = c1N + c2(N − 1) + c3(N − 1) + c4 N(N+1) 2 − 1 + ... c5 N(N−1) 2 + c6 N(N−1) 2 + c7 (N − 1) This can be reduced to something like... T(N) = aN2 + bN + c 33 / 36
  • 80. Building a function for Analyzing Complexities What can we do with all these quantities? Sum them all to get a step count that can be related to computational complexities!!! Counting Equation T(N) = c1N + c2(N − 1) + c3(N − 1) + c4 N(N+1) 2 − 1 + ... c5 N(N−1) 2 + c6 N(N−1) 2 + c7 (N − 1) This can be reduced to something like... T(N) = aN2 + bN + c 33 / 36
  • 81. Building a function for Analyzing Complexities What can we do with all these quantities? Sum them all to get a step count that can be related to computational complexities!!! Counting Equation T(N) = c1N + c2(N − 1) + c3(N − 1) + c4 N(N+1) 2 − 1 + ... c5 N(N−1) 2 + c6 N(N−1) 2 + c7 (N − 1) This can be reduced to something like... T(N) = aN2 + bN + c 33 / 36
  • 82. Building a function for Analyzing Complexities What can we do with all these quantities? Sum them all to get a step count that can be related to computational complexities!!! Counting Equation T(N) = c1N + c2(N − 1) + c3(N − 1) + c4 N(N+1) 2 − 1 + ... c5 N(N−1) 2 + c6 N(N−1) 2 + c7 (N − 1) This can be reduced to something like... T(N) = aN2 + bN + c 33 / 36
  • 83. Outline 1 Motivation What is an Algorithm? Instance of a Problem Kolmogorov’s Definition 2 Problems Solved By Algorithms What Problems Are Solved By Algorithms? 3 Syllabus Subjects for the Class 4 Some Notes in Notation Before Anything, The Notation for Pseudo-Code 5 What abstraction of a Computer to use? The Random-Access Machine (RAM) Machine 6 Analyzing Algorithms How Input Size affects Running Time The First Method: Counting Number of Operations Counting Equation For Insertion Sort The Analysis of the Best and Worst Case Inputs 34 / 36
  • 84. The Worst and The Average 1 The Worst Case 2 The Average Case Worst Sequence Upper bound on the running time of an algorithm. In case of insertion sort, it will be the permutation: N, N − 1, N − 2, ..., 3, 2, 1 35 / 36
  • 85. The Worst and The Average 1 The Worst Case 2 The Average Case Average Sequence In the case of insertion sort, when half of the elements of A[1, 2, ..., j − 1] are less than A[j] and half are greater. Then, there is only the need to check half of the elements i.e. j 2. 35 / 36
  • 86. WHY TO LOOK FOR EFFICIENT ALGORITHMS? Example 1 Insertion Sort 2 Merge Sort 3 Constraints for the example 4 Final Result Example T(N) = c1N2 36 / 36
  • 87. WHY TO LOOK FOR EFFICIENT ALGORITHMS? Example 1 Insertion Sort 2 Merge Sort 3 Constraints for the example 4 Final Result Example T(N) = c2N log2 N 36 / 36
  • 88. WHY TO LOOK FOR EFFICIENT ALGORITHMS? Example 1 Insertion Sort 2 Merge Sort 3 Constraints for the example 4 Final Result Example Assume, we have 106 numbers to sort, c1 = 2 for a supercomputer and c2 = 50 for a PC. The supercomputer can do 1010 instructions per second. The PC can do 107 instructions per second. 36 / 36
  • 89. WHY TO LOOK FOR EFFICIENT ALGORITHMS? Example 1 Insertion Sort 2 Merge Sort 3 Constraints for the example 4 Final Result Example Insertion Sort in the Supercomputer 2(106)2 ins 1010 ins/sec = 200sec Merge Sort in the Humble PC 2(106) log(106) ins 107 ins/sec = 3.9sec 36 / 36