SlideShare ist ein Scribd-Unternehmen logo
1 von 27
CS 6212 – Design and Analysis
of Algorithms
INTRODUCTION AND
ASYMPTOTIC NOTATION
 Instructor
Prof. Amrinder Arora
amrinder@gwu.edu
Please copy TA on emails
Please feel free to call as well

 Available for study sessions
Science and Engineering Hall
GWU
Algorithms Introduction and Asymptotic Notation 2
LOGISTICS
Algorithms
Analysis
Asymptotic
NP-
Completeness
Design
D&C
DP
Greedy
Graph
B&B
Applications
Algorithms Introduction and Asymptotic Notation 3
COURSE OUTLINE
Design and Analysis of Algorithms
 Designing – Algorithmic Techniques
 Analyzing – how much time an algorithm takes
 Proving inherent complexity of problems
4
PURPOSE OF THIS CLASS
Algorithms Introduction and Asymptotic Notation
 A precise statement to solve a problem on a computer
 A sequence of definite instructions to do a certain job
5
“ALGORITHM” – DEFINITIONS
Algorithms Introduction and Asymptotic Notation
Pseudo-code consisting of:
 Variables
 Assignments
 Arrays
 Reading/Writing data
 Loops
 Switch/Case
 Function/Procedure
 Begin/End
Algorithms Introduction and Asymptotic Notation 6
REPRESENTING AN ALGORITHM
Given: An array A of n numbers
Purpose: To sort the array
Algorithm:
for j = 1 to n-1
key = A[j]
// A[j] is added in the sorted sequence A[1.. j-1]
i = j - 1
while i >= 0 and A [i] > key
A[ i + 1] = A[i]
i = i - 1
A [i +1] = key
7
EXAMPLE 1: INSERTION SORT
Algorithms Introduction and Asymptotic Notation
 Best case running time
 Worst case running time
 Average case running time
8
EXAMPLE 2: EUCLID’S ALGORITHM (CONT.)
gcd(n,m) {
r = n%m
if r == 0 return m
// else
return gcd(m, r)
}
Algorithms Introduction and Asymptotic Notation
BinarySearch(A[0..N-1], value, low, high)
{
if (high < low)
return -1 // not found
mid = (low + high) / 2
if (A[mid] > value)
return BinarySearch(A, value, low, mid-1)
else if (A[mid] < value)
return BinarySearch(A, value, mid+1, high)
else return mid // found
}
9
EXAMPLE 3: BINARY SEARCH
Algorithms Introduction and Asymptotic Notation
 How long will the algorithm take?
 How much memory will it require?
For Example:
Function sum (array a) {
sum = 0;
for (int j : a) {
sum = sum + j
}
return sum;
}
10
ANALYZING AN ALGORITHM
Algorithms Introduction and Asymptotic Notation
 Why to do it?
 A priori estimation of performance
 To compare algorithms on a level playing field
 How to do it? (What is the model?)
 Random access memory model
 Math operations take constant time
 Read/write operations take constant time
 What do we compute?
 Time complexity: # of operations as a function of input size
 Space complexity: # of bits used
11
ANALYZING AN ALGORITHM
Algorithms Introduction and Asymptotic Notation
How to Analyze a Given Algorithm (Program)
Some tips:
 When analyzing an if then else condition, consider the arm
that takes the longest time
 When considering a loop, take the sum
 When considering a nested loop, …
Algorithms Introduction and Asymptotic Notation 12
ANALYZING ALGORITHMS
j = 1
while (j < n) {
k = 2
while (k < n) {
Sum += a[j]*b[k]
k = k * k
}
j++
}
(n log log n)
For (int j = 1 to n) {
For (int k = j to n) {
x = k
While (x < n) {
Sum +=
a[j]*b[k]*c[x]
If (x % 3 == 0) {
x = n + 1
}
x = x + 1
}
}
}
For (int j = 1 to n) {
k = j
while (k < n) {
Sum += a[k]*b[k]
k += log n
}
}
Algorithms Introduction and Asymptotic Notation 13
WHAT IS THE TIME COMPLEXITY OF THIS
PROGRAM?
Possible Quiz Questions
 Sets, functions
 Logs and Exponents
 Recurrence Relations
 Sums of series
 Arithmetic Progression: 1 + 2 + 3 + … + n
 Geometric Progress: 1 + 3 + 9 + … 3k
 AGP: 1 + 2.3 + 3.9 + … (k+1) 3k
 Others: 12 + 22 + 32 + … + n2, Harmonic Series
14
REQUIRED MATH CONSTRUCTS
Algorithms Introduction and Asymptotic Notation
Simulation/Runoff
(on worst
case/average case)
•Provides incomplete
picture
•Works for complex
functions
Analysis and
comparison of
Asymptotic notation
•Provides a complete
theoretical
understanding
•May not work for
very complex
algorithms
15
COMPARING ALGORITHMS
Algorithms Introduction and Asymptotic Notation
 Big O notation
 f(n) = O(g(n)) if there exist constants n0 and c such that f(n) ≤ c g(n)
for all n ≥ n0.
For example, consider f(n) = n, and g(n) = n2. Then, f(n) = O(g(n))
If f(n) = a0 n0 + a1 n1 + … + am nm,
then f(n) = O (nm)
 Big Omega notation
 f(n) = Ω(g(n)) if there exist constants n0 and c such that f(n) ≥ c g(n)
for all n ≥ n0.
16
ASYMPTOTIC NOTATION
Algorithms Introduction and Asymptotic Notation
 Small o notation
 f(n) = o(g(n)) if for any constant c > 0, there exists n0 such that 0 ≤
f(n) < c g(n) for all n ≥ n0.
For example, n = o(n2)
 Small omega () notation
 f(n) = (g(n)) if for any constant c > 0, there exists n0 such that f(n) ≥
c g(n) ≥ 0, for all n ≥ n0
For example, n3 = (n2)
17
ASYMPTOTIC NOTATIONS (CONT.)
Algorithms Introduction and Asymptotic Notation
 f(n) = O(g(n)) if and only if g(n) = Ω(f(n))
 If f(n) = O(g(n)) and g(n) = O(f(n)), then f(n) = (g(n))
 f(n) = o(g(n)) if and only if g(n) = (f(n))
 f(n) = o(g(n)) implies limnf(n)/g(n) = 0
18
ASYMPTOTIC NOTATIONS (CONT.)
Algorithms Introduction and Asymptotic Notation
 In some cases, we need to use the L’Hopital’s rule to prove
the small oh notation. L’Hopital’s rule states that assuming
certain conditions hold,
 For example, suppose we want to prove the following:
(log n)3 + 3 (log n)2 = o(n)
 We can find the limit of these functions as follows:
limn(log n)3 + 3 (log n)2 / n
= limn6 (log n)2 + 12 log n / n1/2 // Using L’Hopital’s rule
= limn24 log n + 24/ n1/2 // Using L’Hopital’s rule
= limn48/ n1/2 // Using L’Hopital’s rule
= 0
Algorithms Introduction and Asymptotic Notation 19
PROVING SMALL OH USING L’HOPITAL’S
RULE
O o   Ω
≤ < = > ≥
20
ASYMPTOTIC NOTATIONS (CONT.)
Analogy with real numbers
Algorithms Introduction and Asymptotic Notation
Which properties apply to which (of
5) asymptotic notations?
 Transitivity
 Reflexivity
 Symmetry
 Transpose Symmetry
 Trichotomy
21
ASYMPTOTIC NOTATIONS (CONT.)
Algorithms Introduction and Asymptotic Notation
Which properties apply to which (of
5) asymptotic notations?
 Transitivity: O, o, , , Ω
 Reflexivity: O, , Ω
 Symmetry: 
 Transpose Symmetry: (O with Ω, o with )
 Trichotomy: Does not hold. For real numbers x
and y, we can always say that either x < y or x =
y or x > y. For functions, we may not be able to
say that. For example if f(n) = sin(n) and
g(n)=cos(n)
22
ASYMPTOTIC NOTATIONS (CONT.)
Algorithms Introduction and Asymptotic Notation
LOGISTICS
 Rigor required by this class
 Saturday study sessions (Optional)
 Study sessions on other days – You need to coordinate
 Grading – Review course information sheet in Blackboard
23Algorithms Introduction and Asymptotic Notation
SOME LESSONS FROM PREVIOUS CLASSES
 Almost no correlation between grades and background
 Correlation between grades and number of classes attended
 Correlation between grades and time spent on course
 Strong correlation between grades and homeworks/projects
24Algorithms Introduction and Asymptotic Notation
80% OF
SUCCESS IS
SHOWING UP.
Algorithms Introduction and Asymptotic Notation 25
 Review Project P1
 Review HW1
 Review Course Outline
Algorithms Introduction and Asymptotic Notation 26
READING ASSIGNMENTS
 http://en.wikipedia.org/wiki/Arithmetic_progression
 http://en.wikipedia.org/wiki/Geometric_series
 https://www.boundless.com/algebra/textbooks/boundless-
algebra-textbook/sequences-series-and-combinatorics-
8/sequences-and-series-53/introduction-to-sequences-224-
5904/
 http://en.wikipedia.org/wiki/L%27H%C3%B4pital%27s_rule
 https://www.youtube.com/watch?v=PdSzruR5OeE
Algorithms Introduction and Asymptotic Notation 27
HELPFUL LINKS

Weitere ähnliche Inhalte

Was ist angesagt?

how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
Sajid Marwat
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Ehtisham Ali
 
03 algorithm properties
03 algorithm properties03 algorithm properties
03 algorithm properties
Lincoln School
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Nikhil Sharma
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
Gayathri Gaayu
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
Ankit Katiyar
 

Was ist angesagt? (20)

Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysis
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
 
03 algorithm properties
03 algorithm properties03 algorithm properties
03 algorithm properties
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Complexity analysis - The Big O Notation
Complexity analysis - The Big O NotationComplexity analysis - The Big O Notation
Complexity analysis - The Big O Notation
 
Chapter 09 design and analysis of algorithms
Chapter 09  design and analysis of algorithmsChapter 09  design and analysis of algorithms
Chapter 09 design and analysis of algorithms
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
CS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of AlgorithmsCS8461 - Design and Analysis of Algorithms
CS8461 - Design and Analysis of Algorithms
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
 

Ähnlich wie Introduction to Algorithms and Asymptotic Notation

DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..
KarthikeyaLanka1
 
Lec03 04-time complexity
Lec03 04-time complexityLec03 04-time complexity
Lec03 04-time complexity
Abbas Ali
 
Data structures notes for college students btech.pptx
Data structures notes for college students btech.pptxData structures notes for college students btech.pptx
Data structures notes for college students btech.pptx
KarthikVijay59
 

Ähnlich wie Introduction to Algorithms and Asymptotic Notation (20)

Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
 
DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..
 
Lec03 04-time complexity
Lec03 04-time complexityLec03 04-time complexity
Lec03 04-time complexity
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
 
Unit 1
Unit 1Unit 1
Unit 1
 
Lec1
Lec1Lec1
Lec1
 
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptx
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpall...
Algorithm Class at KPHB  (C, C++ Course Training Institute in KPHB, Kukatpall...Algorithm Class at KPHB  (C, C++ Course Training Institute in KPHB, Kukatpall...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpall...
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
Brief introduction to Algorithm analysis
Brief introduction to Algorithm analysis Brief introduction to Algorithm analysis
Brief introduction to Algorithm analysis
 
Data Structures and Algorithms - Lec 02.pdf
Data Structures and Algorithms - Lec 02.pdfData Structures and Algorithms - Lec 02.pdf
Data Structures and Algorithms - Lec 02.pdf
 
Data_Structure_and_Algorithms_Lecture_1.ppt
Data_Structure_and_Algorithms_Lecture_1.pptData_Structure_and_Algorithms_Lecture_1.ppt
Data_Structure_and_Algorithms_Lecture_1.ppt
 
Daa unit 6_efficiency of algorithms
Daa unit 6_efficiency of algorithmsDaa unit 6_efficiency of algorithms
Daa unit 6_efficiency of algorithms
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
 
Data structures notes for college students btech.pptx
Data structures notes for college students btech.pptxData structures notes for college students btech.pptx
Data structures notes for college students btech.pptx
 
Data Structure: Algorithm and analysis
Data Structure: Algorithm and analysisData Structure: Algorithm and analysis
Data Structure: Algorithm and analysis
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture Notes
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1
 

Mehr von Amrinder Arora

Mehr von Amrinder Arora (20)

Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
 
NP-Completeness - II
NP-Completeness - IINP-Completeness - II
NP-Completeness - II
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First Search
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search Traversal
 
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaArima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
 
Online algorithms in Machine Learning
Online algorithms in Machine LearningOnline algorithms in Machine Learning
Online algorithms in Machine Learning
 
NP completeness
NP completenessNP completeness
NP completeness
 
Algorithmic Puzzles
Algorithmic PuzzlesAlgorithmic Puzzles
Algorithmic Puzzles
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisEuclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part II
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
 
Set Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersSet Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom Filters
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci Heaps
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresR-Trees and Geospatial Data Structures
R-Trees and Geospatial Data Structures
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Introduction to Algorithms and Asymptotic Notation

  • 1. CS 6212 – Design and Analysis of Algorithms INTRODUCTION AND ASYMPTOTIC NOTATION
  • 2.  Instructor Prof. Amrinder Arora amrinder@gwu.edu Please copy TA on emails Please feel free to call as well   Available for study sessions Science and Engineering Hall GWU Algorithms Introduction and Asymptotic Notation 2 LOGISTICS
  • 4. Design and Analysis of Algorithms  Designing – Algorithmic Techniques  Analyzing – how much time an algorithm takes  Proving inherent complexity of problems 4 PURPOSE OF THIS CLASS Algorithms Introduction and Asymptotic Notation
  • 5.  A precise statement to solve a problem on a computer  A sequence of definite instructions to do a certain job 5 “ALGORITHM” – DEFINITIONS Algorithms Introduction and Asymptotic Notation
  • 6. Pseudo-code consisting of:  Variables  Assignments  Arrays  Reading/Writing data  Loops  Switch/Case  Function/Procedure  Begin/End Algorithms Introduction and Asymptotic Notation 6 REPRESENTING AN ALGORITHM
  • 7. Given: An array A of n numbers Purpose: To sort the array Algorithm: for j = 1 to n-1 key = A[j] // A[j] is added in the sorted sequence A[1.. j-1] i = j - 1 while i >= 0 and A [i] > key A[ i + 1] = A[i] i = i - 1 A [i +1] = key 7 EXAMPLE 1: INSERTION SORT Algorithms Introduction and Asymptotic Notation
  • 8.  Best case running time  Worst case running time  Average case running time 8 EXAMPLE 2: EUCLID’S ALGORITHM (CONT.) gcd(n,m) { r = n%m if r == 0 return m // else return gcd(m, r) } Algorithms Introduction and Asymptotic Notation
  • 9. BinarySearch(A[0..N-1], value, low, high) { if (high < low) return -1 // not found mid = (low + high) / 2 if (A[mid] > value) return BinarySearch(A, value, low, mid-1) else if (A[mid] < value) return BinarySearch(A, value, mid+1, high) else return mid // found } 9 EXAMPLE 3: BINARY SEARCH Algorithms Introduction and Asymptotic Notation
  • 10.  How long will the algorithm take?  How much memory will it require? For Example: Function sum (array a) { sum = 0; for (int j : a) { sum = sum + j } return sum; } 10 ANALYZING AN ALGORITHM Algorithms Introduction and Asymptotic Notation
  • 11.  Why to do it?  A priori estimation of performance  To compare algorithms on a level playing field  How to do it? (What is the model?)  Random access memory model  Math operations take constant time  Read/write operations take constant time  What do we compute?  Time complexity: # of operations as a function of input size  Space complexity: # of bits used 11 ANALYZING AN ALGORITHM Algorithms Introduction and Asymptotic Notation
  • 12. How to Analyze a Given Algorithm (Program) Some tips:  When analyzing an if then else condition, consider the arm that takes the longest time  When considering a loop, take the sum  When considering a nested loop, … Algorithms Introduction and Asymptotic Notation 12 ANALYZING ALGORITHMS
  • 13. j = 1 while (j < n) { k = 2 while (k < n) { Sum += a[j]*b[k] k = k * k } j++ } (n log log n) For (int j = 1 to n) { For (int k = j to n) { x = k While (x < n) { Sum += a[j]*b[k]*c[x] If (x % 3 == 0) { x = n + 1 } x = x + 1 } } } For (int j = 1 to n) { k = j while (k < n) { Sum += a[k]*b[k] k += log n } } Algorithms Introduction and Asymptotic Notation 13 WHAT IS THE TIME COMPLEXITY OF THIS PROGRAM? Possible Quiz Questions
  • 14.  Sets, functions  Logs and Exponents  Recurrence Relations  Sums of series  Arithmetic Progression: 1 + 2 + 3 + … + n  Geometric Progress: 1 + 3 + 9 + … 3k  AGP: 1 + 2.3 + 3.9 + … (k+1) 3k  Others: 12 + 22 + 32 + … + n2, Harmonic Series 14 REQUIRED MATH CONSTRUCTS Algorithms Introduction and Asymptotic Notation
  • 15. Simulation/Runoff (on worst case/average case) •Provides incomplete picture •Works for complex functions Analysis and comparison of Asymptotic notation •Provides a complete theoretical understanding •May not work for very complex algorithms 15 COMPARING ALGORITHMS Algorithms Introduction and Asymptotic Notation
  • 16.  Big O notation  f(n) = O(g(n)) if there exist constants n0 and c such that f(n) ≤ c g(n) for all n ≥ n0. For example, consider f(n) = n, and g(n) = n2. Then, f(n) = O(g(n)) If f(n) = a0 n0 + a1 n1 + … + am nm, then f(n) = O (nm)  Big Omega notation  f(n) = Ω(g(n)) if there exist constants n0 and c such that f(n) ≥ c g(n) for all n ≥ n0. 16 ASYMPTOTIC NOTATION Algorithms Introduction and Asymptotic Notation
  • 17.  Small o notation  f(n) = o(g(n)) if for any constant c > 0, there exists n0 such that 0 ≤ f(n) < c g(n) for all n ≥ n0. For example, n = o(n2)  Small omega () notation  f(n) = (g(n)) if for any constant c > 0, there exists n0 such that f(n) ≥ c g(n) ≥ 0, for all n ≥ n0 For example, n3 = (n2) 17 ASYMPTOTIC NOTATIONS (CONT.) Algorithms Introduction and Asymptotic Notation
  • 18.  f(n) = O(g(n)) if and only if g(n) = Ω(f(n))  If f(n) = O(g(n)) and g(n) = O(f(n)), then f(n) = (g(n))  f(n) = o(g(n)) if and only if g(n) = (f(n))  f(n) = o(g(n)) implies limnf(n)/g(n) = 0 18 ASYMPTOTIC NOTATIONS (CONT.) Algorithms Introduction and Asymptotic Notation
  • 19.  In some cases, we need to use the L’Hopital’s rule to prove the small oh notation. L’Hopital’s rule states that assuming certain conditions hold,  For example, suppose we want to prove the following: (log n)3 + 3 (log n)2 = o(n)  We can find the limit of these functions as follows: limn(log n)3 + 3 (log n)2 / n = limn6 (log n)2 + 12 log n / n1/2 // Using L’Hopital’s rule = limn24 log n + 24/ n1/2 // Using L’Hopital’s rule = limn48/ n1/2 // Using L’Hopital’s rule = 0 Algorithms Introduction and Asymptotic Notation 19 PROVING SMALL OH USING L’HOPITAL’S RULE
  • 20. O o   Ω ≤ < = > ≥ 20 ASYMPTOTIC NOTATIONS (CONT.) Analogy with real numbers Algorithms Introduction and Asymptotic Notation
  • 21. Which properties apply to which (of 5) asymptotic notations?  Transitivity  Reflexivity  Symmetry  Transpose Symmetry  Trichotomy 21 ASYMPTOTIC NOTATIONS (CONT.) Algorithms Introduction and Asymptotic Notation
  • 22. Which properties apply to which (of 5) asymptotic notations?  Transitivity: O, o, , , Ω  Reflexivity: O, , Ω  Symmetry:   Transpose Symmetry: (O with Ω, o with )  Trichotomy: Does not hold. For real numbers x and y, we can always say that either x < y or x = y or x > y. For functions, we may not be able to say that. For example if f(n) = sin(n) and g(n)=cos(n) 22 ASYMPTOTIC NOTATIONS (CONT.) Algorithms Introduction and Asymptotic Notation
  • 23. LOGISTICS  Rigor required by this class  Saturday study sessions (Optional)  Study sessions on other days – You need to coordinate  Grading – Review course information sheet in Blackboard 23Algorithms Introduction and Asymptotic Notation
  • 24. SOME LESSONS FROM PREVIOUS CLASSES  Almost no correlation between grades and background  Correlation between grades and number of classes attended  Correlation between grades and time spent on course  Strong correlation between grades and homeworks/projects 24Algorithms Introduction and Asymptotic Notation
  • 25. 80% OF SUCCESS IS SHOWING UP. Algorithms Introduction and Asymptotic Notation 25
  • 26.  Review Project P1  Review HW1  Review Course Outline Algorithms Introduction and Asymptotic Notation 26 READING ASSIGNMENTS
  • 27.  http://en.wikipedia.org/wiki/Arithmetic_progression  http://en.wikipedia.org/wiki/Geometric_series  https://www.boundless.com/algebra/textbooks/boundless- algebra-textbook/sequences-series-and-combinatorics- 8/sequences-and-series-53/introduction-to-sequences-224- 5904/  http://en.wikipedia.org/wiki/L%27H%C3%B4pital%27s_rule  https://www.youtube.com/watch?v=PdSzruR5OeE Algorithms Introduction and Asymptotic Notation 27 HELPFUL LINKS