SlideShare a Scribd company logo
Chapter 2Chapter 2
Complexity analysisComplexity analysis
01/29/18 BY MS. SHAISTA QADIR 1
PRESENTED BY
Shaista Qadir
Lecturer king khalid university
ContentsContents
 algorithm and its properties
 Computational Complexity
 time Complexity
 spaCe Complexity
 Complexity analysis and asymptotiC
notations.
 Big-oh-notation (o)
 omega-notation ( )Ω
 theta-notation ( )Θ
 the Best, average, and Worst Case analyses.
 Complexity analyses examples.
 Comparing groWth rates
01/29/18 BY MS. SHAISTA QADIR 2
algorithm and itsalgorithm and its
propertiesproperties
01/29/18 BY MS. SHAISTA QADIR 3
 An algorithm is a step by step procedure for calculating a
function.
 An algorithm can exist for a day to day task, a simple
program or a complex calculation.
 To write an algorithm for a problem one should know
◦ The input to be supplied for the program.
◦ The operation to be performed on the input to perform the
task.
◦ The output to be obtained.
◦ Any assumptions or initializations to be made for solving
the problem.
algorithm and itsalgorithm and its
propertiesproperties
01/29/18 BY MS. SHAISTA QADIR 4
 An algorithm for a problem has the following properties:
 Finiteness: An algorithm should have a finite number of steps
and should terminate after these finite number of steps.
 Definiteness: Every step in the algorithm should be very clear.
The steps shall be explained in only one way and executed
without any confusion.
 Effectiveness: The instructions of the algorithm are realizable.
The steps in the algorithm shall be executed in finite amount of
time.
 Input: An algorithm can accept no input or it can accept one to
many inputs.
 Output: The algorithm should produce a minimum of one
output.
Computational ComplexityComputational Complexity
01/29/18 BY MS. SHAISTA QADIR 5
 The same problem can frequently be solved with
algorithms that differ in efficiency.
 To compare the efficiency of algorithms, a measure of
the degree of difficulty of an algorithm called
computational complexity was developed by Juris
Hartmanis and Richard E.Stearns.
 Computational complexity indicates how much effort is
needed to apply an algorithm or how costly it is.
 Computational Complexity is measured in terms of two
efficiencies to design good algorithms.
◦ Space efficiency
◦ Time efficiency
Computational ComplexityComputational Complexity
(( SpaCe effiCienCySpaCe effiCienCy ))
01/29/18 BY MS. SHAISTA QADIR 6
 These efficiency measures helps us to understand which
algorithm is better than other.
 Space Efficiency:
◦ Space Efficiency is on how efficiently the algorithm
consumes memory space.
◦ Space required will depend upon
 program size (constant)
 data size (constant and dynamic)
◦ These days machines come with large memory sizes to
solve this problem.
Computational ComplexityComputational Complexity
( SpaCe effiCienCy )( SpaCe effiCienCy )
01/29/18 BY MS. SHAISTA QADIR 7
 Two space Components
◦ Fixed static part (Cp): space for numbers, constants,
size of input, output and program .
◦ Variable dynamic part (Sp): space for variables whose
size is problem dependent and dynamic.
 Total space requirement for an algorithm is the sum of
fixed and dynamic part.
◦ S(P)= Cp+Sp
Computational ComplexityComputational Complexity
( illuStration )( illuStration )
01/29/18 BY MS. SHAISTA QADIR 8
 Illustration: Find the total space requirement for the
following pieces of codes (neglect program space
requirement)
◦ i) code to find difference between two numbers.
int x,y,dif;
dif = x-y;
 Here there are three static variables x, y, dif and no
dynamic variables. Space allotted for int variable is 4
bytes.
 Therefore, S(P)= Cp+Sp
 S(P)= 3x4+0 =12 bytes
Computational ComplexityComputational Complexity
( illuStration )( illuStration )
01/29/18 BY MS. SHAISTA QADIR 9
◦ ii) code to add numbers of array.
int add(int x[], int n)
{ int total = 0, i;
for(i=0; i<n; i++)
total = total + x[i];
return total; }
 Here there are three static variables, int n, total, i and one
dynamic variable int x which depends upon the value n.
 Space allotted for int variable is 4 bytes.
◦ Therefore, S(P)= Cp+Sp
◦ S(P)= (3x4)+(nx4)
◦ S(P) =12 + (nx4) bytes
Computational ComplexityComputational Complexity
( time effiCenCy )( time effiCenCy )
01/29/18 BY MS. SHAISTA QADIR 10
 Time Efficiency
◦ is determined based on the amount of time required to run
a program.
◦ It depends upon the number of instructions to be executed
which in turn is dependent on the amount of data. It is
hardware independent.
 Time Efficiency/ Time Complexity analysis is essential to know
◦ If the algorithm is “fast enough” for my needs
◦ How longer will the algorithm take if I increase the amount
of data it must process?
◦ Which is the right algorithm, among the given a set of
algorithms that accomplish the same thing.
Computational ComplexityComputational Complexity
( illustration )( illustration )
01/29/18 BY MS. SHAISTA QADIR 11
 Consider the piece of code
for (int i=1; i<= n ; i++)
for int j=1 ; j <= n; j++)
{
cout << i; 1
p = p + i; 1 2n (2n)n
}
 The 1st loop runs n times, 2nd loop runs n times, the
third and fourth statements run 1 unit each.
 So the total run-time is equal to 2n2
Complexity analysis andComplexity analysis and
asymptotiC notationsasymptotiC notations
01/29/18 BY MS. SHAISTA QADIR 12
 To analyze the computational complexity of algorithms
in terms of time, computer scientists used several
asymptotic notations and important notations among
them are:
 Big-oh-notation (O)
 Omega-notation (Ω)
 Theta-notation (Θ)
 Asymptotic Notations provides a formula that associates
n, the problem size, with t, the processing time required
to solve the problem.
Complexity analysis and asymptotiCComplexity analysis and asymptotiC
notationsnotations
(Worst Case analyses )(Worst Case analyses )
01/29/18 BY MS. SHAISTA QADIR 13
 Big-oh-notation (O)
Big-O, “bounded above by”
 Let T(n) be a measure of the time required to execute an
algorithm of problem size n.
 then for some positive values of constants c and N, the
Big-Oh (O) of a function f(n) on n is given by
T(n)=O(f(n))
T(n)<=c(f(n)) where n>N
 It gives the maximum value of T(n) or the WORST case
for any possible input.
Complexity analysis and asymptotiCComplexity analysis and asymptotiC
notationsnotations
( Best( Best Case analysis )Case analysis )
01/29/18 BY MS. SHAISTA QADIR 14
 Omega-notation (Ω)
Omega, “bounded below by”
 Let T(n) be a measure of the time required to execute an
algorithm of problem size n.
 then for some positive values of constants c and N, the
Omega (Ω) of a function f(n) on n is given by
T(n)= Ω(f(n))
T(n)>=c(f(n)) where n>N
 It gives the minimum value of T(n) or the BEST case for
any possible input.
Complexity analysis and asymptotiCComplexity analysis and asymptotiC
notationsnotations
( aVeraGe Case analysis )( aVeraGe Case analysis )
01/29/18 BY MS. SHAISTA QADIR 15
 Theta-notation (Θ)
Theta, “bounded above and below”
 Let T(n) be a measure of the time required to execute an
algorithm of problem size n.
 then for some positive values of constants c1, c2 and N,
the Theta (Θ) of a function f(n) on n is given by
T(n)= Θ(f(n))
c (f(n)) <=T(n)<= c1(c2(f(n)) where n>N
 It gives the expected value of T(n) or the AVERAGE case
for any possible input.
Complexity AnAlysis .Complexity AnAlysis .
01/29/18 BY MS. SHAISTA QADIR 16
 Big O or the Order of n measurement or the Worst Case
 is used mostly in the estimation of performance of a
piece of code against the amount of data.
 For the piece of code,
for (int i=1; i<= n ; i++)
for int j=1 ; j <= n; j++)
{ cout << i;
p = p + i;
} T(n)=2n2
Complexity AnAlysisComplexity AnAlysis
( exAmple )( exAmple )
01/29/18 BY MS. SHAISTA QADIR 17
 To find Big O from T(n)= 2n2
1. Discarding constant terms produces :
Here no constants 2n2
2. Clearing coefficients : n2
3. Picking the most significant term: n2
T(n)=O(n2 )
Complexity AnAlysisComplexity AnAlysis
( exAmple s)( exAmple s)
01/29/18 BY MS. SHAISTA QADIR 18
 Example:1
Time =2n3
+2n+100
Step:1 Discarding constant terms produces: 2n3
+2n
Step: 2 Clearing coefficients : n3
+n
Step: 3 Picking the most significant term: n3
Time = O(n3
)
 Example:2
Time =3n3
+150
Step:1 Discarding constant terms produces: 3n3
Step: 2 Clearing coefficients : n3
Step: 3 Picking the most significant term: n3
Time =O(n3
)
CompAring groWtH rAtesCompAring groWtH rAtes
01/29/18 BY MS. SHAISTA QADIR 19
01/29/18 BY MS. SHAISTA QADIR 20
THANK YOUTHANK YOU

More Related Content

What's hot

Bruteforce algorithm
Bruteforce algorithmBruteforce algorithm
Bruteforce algorithm
Rezwan Siam
 
Stressen's matrix multiplication
Stressen's matrix multiplicationStressen's matrix multiplication
Stressen's matrix multiplicationKumar
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
Rajendran
 
Asymptotic notations(Big O, Omega, Theta )
Asymptotic notations(Big O, Omega, Theta )Asymptotic notations(Big O, Omega, Theta )
Asymptotic notations(Big O, Omega, Theta )
swapnac12
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
mustafa sarac
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
Protap Mondal
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
Arvind Krishnaa
 
Master theorem
Master theoremMaster theorem
Master theorem
fika sweety
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
Rajandeep Gill
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
Ganesh Solanke
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Dr Shashikant Athawale
 
Lecture 2 data structures and algorithms
Lecture 2 data structures and algorithmsLecture 2 data structures and algorithms
Lecture 2 data structures and algorithmsAakash deep Singhal
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)
jehan1987
 
Lecture optimal binary search tree
Lecture optimal binary search tree Lecture optimal binary search tree
Lecture optimal binary search tree
Divya Ks
 
Intermediate code generator
Intermediate code generatorIntermediate code generator
Intermediate code generator
sanchi29
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
Rishabh Soni
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Big o notation
Big o notationBig o notation
Big o notation
hamza mushtaq
 
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 algortihmSajid Marwat
 
Graph coloring problem
Graph coloring problemGraph coloring problem
Graph coloring problem
V.V.Vanniaperumal College for Women
 

What's hot (20)

Bruteforce algorithm
Bruteforce algorithmBruteforce algorithm
Bruteforce algorithm
 
Stressen's matrix multiplication
Stressen's matrix multiplicationStressen's matrix multiplication
Stressen's matrix multiplication
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
Asymptotic notations(Big O, Omega, Theta )
Asymptotic notations(Big O, Omega, Theta )Asymptotic notations(Big O, Omega, Theta )
Asymptotic notations(Big O, Omega, Theta )
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Master theorem
Master theoremMaster theorem
Master theorem
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Lecture 2 data structures and algorithms
Lecture 2 data structures and algorithmsLecture 2 data structures and algorithms
Lecture 2 data structures and algorithms
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)
 
Lecture optimal binary search tree
Lecture optimal binary search tree Lecture optimal binary search tree
Lecture optimal binary search tree
 
Intermediate code generator
Intermediate code generatorIntermediate code generator
Intermediate code generator
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
 
Big o notation
Big o notationBig o notation
Big o notation
 
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
 
Graph coloring problem
Graph coloring problemGraph coloring problem
Graph coloring problem
 

Similar to Complexity Analysis

Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
MemMem25
 
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptxData Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
RashidFaridChishti
 
Big Oh.ppt
Big Oh.pptBig Oh.ppt
Big Oh.ppt
Senthil Vit
 
Analysis of Algorithum
Analysis of AlgorithumAnalysis of Algorithum
Analysis of Algorithum
Ain-ul-Moiz Khawaja
 
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
TechVision8
 
Lec7
Lec7Lec7
Lec7.ppt
Lec7.pptLec7.ppt
Lec7.ppt
Agung Kurniawan
 
Lec7.ppt
Lec7.pptLec7.ppt
Lec7.ppt
NikhilKatariya8
 
analysis of algorithms
analysis of algorithmsanalysis of algorithms
analysis of algorithms
MyMovies15
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
Venkatesh Iyer
 
Asymptotic Analysis in Data Structure using C
Asymptotic Analysis in Data Structure using CAsymptotic Analysis in Data Structure using C
Asymptotic Analysis in Data Structure using C
Meghaj Mallick
 
DESIGN AND ALGORITHM.pptx BCA BANGALORECITY UNIVERSITY
DESIGN AND ALGORITHM.pptx BCA BANGALORECITY UNIVERSITYDESIGN AND ALGORITHM.pptx BCA BANGALORECITY UNIVERSITY
DESIGN AND ALGORITHM.pptx BCA BANGALORECITY UNIVERSITY
AneetaGrace1
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm Analysis
Mary Margarat
 
Ch-2 final exam documet compler design elements
Ch-2 final exam documet compler design elementsCh-2 final exam documet compler design elements
Ch-2 final exam documet compler design elements
MAHERMOHAMED27
 
Lec1
Lec1Lec1
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptx
NishaS88
 
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
 
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
 
Chapter two
Chapter twoChapter two
Chapter two
mihiretu kassaye
 
3 analysis.gtm
3 analysis.gtm3 analysis.gtm
3 analysis.gtm
Natarajan Angappan
 

Similar to Complexity Analysis (20)

Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
 
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptxData Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
 
Big Oh.ppt
Big Oh.pptBig Oh.ppt
Big Oh.ppt
 
Analysis of Algorithum
Analysis of AlgorithumAnalysis of Algorithum
Analysis of Algorithum
 
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
Data Structures and Algorithms Lecture 2: Analysis of Algorithms, Asymptotic ...
 
Lec7
Lec7Lec7
Lec7
 
Lec7.ppt
Lec7.pptLec7.ppt
Lec7.ppt
 
Lec7.ppt
Lec7.pptLec7.ppt
Lec7.ppt
 
analysis of algorithms
analysis of algorithmsanalysis of algorithms
analysis of algorithms
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
Asymptotic Analysis in Data Structure using C
Asymptotic Analysis in Data Structure using CAsymptotic Analysis in Data Structure using C
Asymptotic Analysis in Data Structure using C
 
DESIGN AND ALGORITHM.pptx BCA BANGALORECITY UNIVERSITY
DESIGN AND ALGORITHM.pptx BCA BANGALORECITY UNIVERSITYDESIGN AND ALGORITHM.pptx BCA BANGALORECITY UNIVERSITY
DESIGN AND ALGORITHM.pptx BCA BANGALORECITY UNIVERSITY
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm Analysis
 
Ch-2 final exam documet compler design elements
Ch-2 final exam documet compler design elementsCh-2 final exam documet compler design elements
Ch-2 final exam documet compler design elements
 
Lec1
Lec1Lec1
Lec1
 
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.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
 
CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of Algorithms
 
Chapter two
Chapter twoChapter two
Chapter two
 
3 analysis.gtm
3 analysis.gtm3 analysis.gtm
3 analysis.gtm
 

More from Shaista Qadir

Lecture 4
Lecture 4Lecture 4
Lecture 4
Shaista Qadir
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
Shaista Qadir
 
Sorting
SortingSorting
Sorting
Shaista Qadir
 
Searching
SearchingSearching
Searching
Shaista Qadir
 
Queue
QueueQueue
linked list
linked listlinked list
linked list
Shaista Qadir
 

More from Shaista Qadir (6)

Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Sorting
SortingSorting
Sorting
 
Searching
SearchingSearching
Searching
 
Queue
QueueQueue
Queue
 
linked list
linked listlinked list
linked list
 

Recently uploaded

Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 

Recently uploaded (20)

Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 

Complexity Analysis

  • 1. Chapter 2Chapter 2 Complexity analysisComplexity analysis 01/29/18 BY MS. SHAISTA QADIR 1 PRESENTED BY Shaista Qadir Lecturer king khalid university
  • 2. ContentsContents  algorithm and its properties  Computational Complexity  time Complexity  spaCe Complexity  Complexity analysis and asymptotiC notations.  Big-oh-notation (o)  omega-notation ( )Ω  theta-notation ( )Θ  the Best, average, and Worst Case analyses.  Complexity analyses examples.  Comparing groWth rates 01/29/18 BY MS. SHAISTA QADIR 2
  • 3. algorithm and itsalgorithm and its propertiesproperties 01/29/18 BY MS. SHAISTA QADIR 3  An algorithm is a step by step procedure for calculating a function.  An algorithm can exist for a day to day task, a simple program or a complex calculation.  To write an algorithm for a problem one should know ◦ The input to be supplied for the program. ◦ The operation to be performed on the input to perform the task. ◦ The output to be obtained. ◦ Any assumptions or initializations to be made for solving the problem.
  • 4. algorithm and itsalgorithm and its propertiesproperties 01/29/18 BY MS. SHAISTA QADIR 4  An algorithm for a problem has the following properties:  Finiteness: An algorithm should have a finite number of steps and should terminate after these finite number of steps.  Definiteness: Every step in the algorithm should be very clear. The steps shall be explained in only one way and executed without any confusion.  Effectiveness: The instructions of the algorithm are realizable. The steps in the algorithm shall be executed in finite amount of time.  Input: An algorithm can accept no input or it can accept one to many inputs.  Output: The algorithm should produce a minimum of one output.
  • 5. Computational ComplexityComputational Complexity 01/29/18 BY MS. SHAISTA QADIR 5  The same problem can frequently be solved with algorithms that differ in efficiency.  To compare the efficiency of algorithms, a measure of the degree of difficulty of an algorithm called computational complexity was developed by Juris Hartmanis and Richard E.Stearns.  Computational complexity indicates how much effort is needed to apply an algorithm or how costly it is.  Computational Complexity is measured in terms of two efficiencies to design good algorithms. ◦ Space efficiency ◦ Time efficiency
  • 6. Computational ComplexityComputational Complexity (( SpaCe effiCienCySpaCe effiCienCy )) 01/29/18 BY MS. SHAISTA QADIR 6  These efficiency measures helps us to understand which algorithm is better than other.  Space Efficiency: ◦ Space Efficiency is on how efficiently the algorithm consumes memory space. ◦ Space required will depend upon  program size (constant)  data size (constant and dynamic) ◦ These days machines come with large memory sizes to solve this problem.
  • 7. Computational ComplexityComputational Complexity ( SpaCe effiCienCy )( SpaCe effiCienCy ) 01/29/18 BY MS. SHAISTA QADIR 7  Two space Components ◦ Fixed static part (Cp): space for numbers, constants, size of input, output and program . ◦ Variable dynamic part (Sp): space for variables whose size is problem dependent and dynamic.  Total space requirement for an algorithm is the sum of fixed and dynamic part. ◦ S(P)= Cp+Sp
  • 8. Computational ComplexityComputational Complexity ( illuStration )( illuStration ) 01/29/18 BY MS. SHAISTA QADIR 8  Illustration: Find the total space requirement for the following pieces of codes (neglect program space requirement) ◦ i) code to find difference between two numbers. int x,y,dif; dif = x-y;  Here there are three static variables x, y, dif and no dynamic variables. Space allotted for int variable is 4 bytes.  Therefore, S(P)= Cp+Sp  S(P)= 3x4+0 =12 bytes
  • 9. Computational ComplexityComputational Complexity ( illuStration )( illuStration ) 01/29/18 BY MS. SHAISTA QADIR 9 ◦ ii) code to add numbers of array. int add(int x[], int n) { int total = 0, i; for(i=0; i<n; i++) total = total + x[i]; return total; }  Here there are three static variables, int n, total, i and one dynamic variable int x which depends upon the value n.  Space allotted for int variable is 4 bytes. ◦ Therefore, S(P)= Cp+Sp ◦ S(P)= (3x4)+(nx4) ◦ S(P) =12 + (nx4) bytes
  • 10. Computational ComplexityComputational Complexity ( time effiCenCy )( time effiCenCy ) 01/29/18 BY MS. SHAISTA QADIR 10  Time Efficiency ◦ is determined based on the amount of time required to run a program. ◦ It depends upon the number of instructions to be executed which in turn is dependent on the amount of data. It is hardware independent.  Time Efficiency/ Time Complexity analysis is essential to know ◦ If the algorithm is “fast enough” for my needs ◦ How longer will the algorithm take if I increase the amount of data it must process? ◦ Which is the right algorithm, among the given a set of algorithms that accomplish the same thing.
  • 11. Computational ComplexityComputational Complexity ( illustration )( illustration ) 01/29/18 BY MS. SHAISTA QADIR 11  Consider the piece of code for (int i=1; i<= n ; i++) for int j=1 ; j <= n; j++) { cout << i; 1 p = p + i; 1 2n (2n)n }  The 1st loop runs n times, 2nd loop runs n times, the third and fourth statements run 1 unit each.  So the total run-time is equal to 2n2
  • 12. Complexity analysis andComplexity analysis and asymptotiC notationsasymptotiC notations 01/29/18 BY MS. SHAISTA QADIR 12  To analyze the computational complexity of algorithms in terms of time, computer scientists used several asymptotic notations and important notations among them are:  Big-oh-notation (O)  Omega-notation (Ω)  Theta-notation (Θ)  Asymptotic Notations provides a formula that associates n, the problem size, with t, the processing time required to solve the problem.
  • 13. Complexity analysis and asymptotiCComplexity analysis and asymptotiC notationsnotations (Worst Case analyses )(Worst Case analyses ) 01/29/18 BY MS. SHAISTA QADIR 13  Big-oh-notation (O) Big-O, “bounded above by”  Let T(n) be a measure of the time required to execute an algorithm of problem size n.  then for some positive values of constants c and N, the Big-Oh (O) of a function f(n) on n is given by T(n)=O(f(n)) T(n)<=c(f(n)) where n>N  It gives the maximum value of T(n) or the WORST case for any possible input.
  • 14. Complexity analysis and asymptotiCComplexity analysis and asymptotiC notationsnotations ( Best( Best Case analysis )Case analysis ) 01/29/18 BY MS. SHAISTA QADIR 14  Omega-notation (Ω) Omega, “bounded below by”  Let T(n) be a measure of the time required to execute an algorithm of problem size n.  then for some positive values of constants c and N, the Omega (Ω) of a function f(n) on n is given by T(n)= Ω(f(n)) T(n)>=c(f(n)) where n>N  It gives the minimum value of T(n) or the BEST case for any possible input.
  • 15. Complexity analysis and asymptotiCComplexity analysis and asymptotiC notationsnotations ( aVeraGe Case analysis )( aVeraGe Case analysis ) 01/29/18 BY MS. SHAISTA QADIR 15  Theta-notation (Θ) Theta, “bounded above and below”  Let T(n) be a measure of the time required to execute an algorithm of problem size n.  then for some positive values of constants c1, c2 and N, the Theta (Θ) of a function f(n) on n is given by T(n)= Θ(f(n)) c (f(n)) <=T(n)<= c1(c2(f(n)) where n>N  It gives the expected value of T(n) or the AVERAGE case for any possible input.
  • 16. Complexity AnAlysis .Complexity AnAlysis . 01/29/18 BY MS. SHAISTA QADIR 16  Big O or the Order of n measurement or the Worst Case  is used mostly in the estimation of performance of a piece of code against the amount of data.  For the piece of code, for (int i=1; i<= n ; i++) for int j=1 ; j <= n; j++) { cout << i; p = p + i; } T(n)=2n2
  • 17. Complexity AnAlysisComplexity AnAlysis ( exAmple )( exAmple ) 01/29/18 BY MS. SHAISTA QADIR 17  To find Big O from T(n)= 2n2 1. Discarding constant terms produces : Here no constants 2n2 2. Clearing coefficients : n2 3. Picking the most significant term: n2 T(n)=O(n2 )
  • 18. Complexity AnAlysisComplexity AnAlysis ( exAmple s)( exAmple s) 01/29/18 BY MS. SHAISTA QADIR 18  Example:1 Time =2n3 +2n+100 Step:1 Discarding constant terms produces: 2n3 +2n Step: 2 Clearing coefficients : n3 +n Step: 3 Picking the most significant term: n3 Time = O(n3 )  Example:2 Time =3n3 +150 Step:1 Discarding constant terms produces: 3n3 Step: 2 Clearing coefficients : n3 Step: 3 Picking the most significant term: n3 Time =O(n3 )
  • 19. CompAring groWtH rAtesCompAring groWtH rAtes 01/29/18 BY MS. SHAISTA QADIR 19
  • 20. 01/29/18 BY MS. SHAISTA QADIR 20 THANK YOUTHANK YOU