SlideShare a Scribd company logo
1 of 17
Step Count Method for
Time Complexity Analysis
What is Time Complexity?
• Time Complexity is the amount of time taken by the algorithm
to run. It measures the time taken to execute each statement of
code in an algorithm.
Time Complexity can be calculated by using :
• Step Count Method with Asymptotic Notation.
What is Step Count Method?
• The step count method is one of the methods to analyze the
Time complexity of an algorithm. In this method, we count the
number of times each instruction is executed. Based on that we
will calculate the Time Complexity.
• The step Count method is also called as Frequency Count
method.
Let us discuss step count for different
statements:
• 1. Comments:
• Comments are used for giving extra meaning to the program.
They are not executed during the execution. Comments are
ignored during execution.
• Therefore the number of times that a comment executes is 0.
(Cont..)
• 2. Conditional statements:
• Conditional statements check the condition and if the condition is correct then
the conditional subpart will be executed. So the execution of conditional
statements happens only once. The compiler will execute the conditional
statements to check whether the condition is correct or not so it will be executed
one time.
• In if-else statements the if statement is executed one time but the else statement
will be executed zero or one time because if the “if” statement is executed then
the else statement will not execute.
• In switch case statements the starting switch(condition) statement will be
executed one time but the inner case statements will execute if none of the
previous case statements are executed.
• In nested if and if else ladder statements also the initial if statement is executed
at least once but inner statements will be executed based on the previous
statements’ execution.
(Cont..)
• 3. Loop statements:
• Loop statements are iterative statements. They are executed one or
more times based on a given condition.
• A typical for(i = 0; i ≤ n; i++) statement will be executed “n+1”
times for the first n times the condition is satisfied and the inner loop
will be executed and for the (n+1)th time the condition is failed and
the loop terminates.
• While: The statement is executed until the given condition is
satisfied.
• Do while: The statement will repeat until the given condition is
satisfied. The do-while statement will execute at least once because
for the first time it will not check the condition.
(Cont..)
• 4. Functions:
• Functions are executed based on the number of times they get
called. If they get called n times they will be executed n times. If
they are not called at least once then they will not be executed.
Other statements like BEGIN, END and goto statements will be
executed one time.
Illustration of Step Count Method:
• Analysis of Linear Search algorithm
• Let us consider a Linear Search Algorithm.
• Linearsearch(arr, n, key)
• {
• i = 0;
• for(i = 0; i < n; i++)
• {
• if(arr[i] == key)
• {
• printf(“Found”);
• }
• }
(Cont..)
• Where,
• i = 0, is an initialization statement and takes O(1) times.
• for(i = 0;i < n ; i++), is a loop and it takes O(n+1) times .
• if(arr[i] == key), is a conditional statement and takes O(1) times.
• printf(“Found”), is a function and that takes O(0)/O(1) times.
• Therefore Total Number of times it is executed is n + 4 times. As we
ignore lower exponents in time complexity total time became O(n).
• Time complexity: O(n).
Auxiliary Space: O(1)
Calculate Time Complexity
Sequential Statements
• If we have statements with basic
operations like comparisons,
assignments, reading a variable.
We can assume they take
constant time each O(1).
• statement1;
• statement2;
• ...
• statementN;
Example:
• function squareSum(a, b, c) {
• const sa = a * a;
• const sb = b * b;
• const sc = c * c;
• const sum = sa + sb + sc;
• return sum;
• }
Conditional Statements
• if (isValid) {
• statement1;
• statement2;
• } else {
• statement3;
• }
• we can express the time
complexity as O(n log n)
Loop Statements
Linear Time Loops
• for (let i = 0; i < array.length; i++)
• {
• statement1;
• statement2;
• }
• All loops that grow
proportionally to the input size
have a linear time complexity
O(n)
Constant-Time Loops
• for (let i = 0; i < 4; i++) {
• statement1;
• statement2;
• }
• That code is O(1) because it no
longer depends on the input
size.
Logarithmic Time Loops
• Consider the following code, where we divide an array in half on each iteration (binary
search)
• function fn1(array, target, low = 0, high = array.length - 1) {
• let mid;
• while ( low <= high ) {
• mid = ( low + high ) / 2;
• if ( target < array[mid] )
• high = mid - 1;
• else if ( target > array[mid] )
• low = mid + 1;
• else break;
• }
• return mid;
• }
• Time complexity: O(log(n))
Nested loops statements
• for (let i = 0; i < n; i++) {
• statement1;
• for (let j = 0; j < m; j++) {
• statement2;
• statement3;
• }
• }
• Time Complexity: O(n^2)
Time Complexity Description
O(1) It is called constant complexity when the algorithm takes the same amount of time regardless of the
input size n.
O(logn) It's called logarithmic complexity when the algorithm takes space proportional to the log of the input
size n.
O(n) It's called linear complexity when an algorithm takes space directly proportional to the input size n.
O(nlogn) It's called log-linear complexity when the space complexity of an algorithm grows proportionally to the
input size n and a logarithmic factor log().
O(n^2) It's called polynomial complexity when the space complexity grows proportionally to the square of the
input size n.
O(2^n) It's called exponential time complexity when an algorithm's growth doubles with each addition to the
input dataset.
Order of Time Complexity

More Related Content

What's hot

Lecture 3 insertion sort and complexity analysis
Lecture 3   insertion sort and complexity analysisLecture 3   insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysisjayavignesh86
 
4 greedy methodnew
4 greedy methodnew4 greedy methodnew
4 greedy methodnewabhinav108
 
First fit , Best fit, Worst fit
First fit , Best fit, Worst fitFirst fit , Best fit, Worst fit
First fit , Best fit, Worst fitShahzeb Amjad
 
Operating Systems Chapter 6 silberschatz
Operating Systems Chapter 6 silberschatzOperating Systems Chapter 6 silberschatz
Operating Systems Chapter 6 silberschatzGiulianoRanauro
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data StructuresSHAKOOR AB
 
File Protection in Operating System
File Protection in Operating SystemFile Protection in Operating System
File Protection in Operating SystemMeghaj Mallick
 
Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computationBipul Roy Bpl
 
Inter process communication
Inter process communicationInter process communication
Inter process communicationMohd Tousif
 
dynamic programming Rod cutting class
dynamic programming Rod cutting classdynamic programming Rod cutting class
dynamic programming Rod cutting classgiridaroori
 
Radix sort presentation
Radix sort presentationRadix sort presentation
Radix sort presentationRatul Hasan
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using BacktrackingAbhishek Singh
 
REGULAR EXPRESSION TO N.F.A
REGULAR EXPRESSION TO N.F.AREGULAR EXPRESSION TO N.F.A
REGULAR EXPRESSION TO N.F.ADev Ashish
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 

What's hot (20)

Matrix multiplication
Matrix multiplicationMatrix multiplication
Matrix multiplication
 
Lecture 3 insertion sort and complexity analysis
Lecture 3   insertion sort and complexity analysisLecture 3   insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysis
 
4 greedy methodnew
4 greedy methodnew4 greedy methodnew
4 greedy methodnew
 
First fit , Best fit, Worst fit
First fit , Best fit, Worst fitFirst fit , Best fit, Worst fit
First fit , Best fit, Worst fit
 
Best,worst,average case .17581556 045
Best,worst,average case .17581556 045Best,worst,average case .17581556 045
Best,worst,average case .17581556 045
 
Operating Systems Chapter 6 silberschatz
Operating Systems Chapter 6 silberschatzOperating Systems Chapter 6 silberschatz
Operating Systems Chapter 6 silberschatz
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
File Protection in Operating System
File Protection in Operating SystemFile Protection in Operating System
File Protection in Operating System
 
Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computation
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
dynamic programming Rod cutting class
dynamic programming Rod cutting classdynamic programming Rod cutting class
dynamic programming Rod cutting class
 
Radix sort presentation
Radix sort presentationRadix sort presentation
Radix sort presentation
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using Backtracking
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
REGULAR EXPRESSION TO N.F.A
REGULAR EXPRESSION TO N.F.AREGULAR EXPRESSION TO N.F.A
REGULAR EXPRESSION TO N.F.A
 
5.1 greedy
5.1 greedy5.1 greedy
5.1 greedy
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 

Similar to Step Count Method for Time Complexity Analysis.pptx

Lecture 5: Asymptotic analysis of algorithms
Lecture 5: Asymptotic analysis of algorithmsLecture 5: Asymptotic analysis of algorithms
Lecture 5: Asymptotic analysis of algorithmsVivek Bhargav
 
UNIT I- Session 3.pptx
UNIT I- Session 3.pptxUNIT I- Session 3.pptx
UNIT I- Session 3.pptxabcdefgh690537
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithmsiqbalphy1
 
18103010 algorithm complexity (iterative)
18103010 algorithm complexity (iterative)18103010 algorithm complexity (iterative)
18103010 algorithm complexity (iterative)AdityaKhandelwal58
 
2. Asymptotic Notations and Complexity Analysis.pptx
2. Asymptotic Notations and Complexity Analysis.pptx2. Asymptotic Notations and Complexity Analysis.pptx
2. Asymptotic Notations and Complexity Analysis.pptxRams715121
 
Ch1. Analysis of Algorithms.pdf
Ch1. Analysis of Algorithms.pdfCh1. Analysis of Algorithms.pdf
Ch1. Analysis of Algorithms.pdfzoric99
 
Python if_else_loop_Control_Flow_Statement
Python if_else_loop_Control_Flow_StatementPython if_else_loop_Control_Flow_Statement
Python if_else_loop_Control_Flow_StatementAbhishekGupta692777
 
Operators loops conditional and statements
Operators loops conditional and statementsOperators loops conditional and statements
Operators loops conditional and statementsVladislav Hadzhiyski
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity CalculationAkhil Kaushik
 
Analysis and Algorithms: basic Introduction
Analysis and Algorithms: basic IntroductionAnalysis and Algorithms: basic Introduction
Analysis and Algorithms: basic Introductionssuseraf8b2f
 
Asymptotic analysis of algorithms.pptx
Asymptotic analysis of algorithms.pptxAsymptotic analysis of algorithms.pptx
Asymptotic analysis of algorithms.pptxRachit Jain
 
Time_Complexity.pptx
Time_Complexity.pptxTime_Complexity.pptx
Time_Complexity.pptxvivekcommon
 

Similar to Step Count Method for Time Complexity Analysis.pptx (20)

Looping statements
Looping statementsLooping statements
Looping statements
 
PYTHON.pptx
PYTHON.pptxPYTHON.pptx
PYTHON.pptx
 
DSA
DSADSA
DSA
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Lecture 5: Asymptotic analysis of algorithms
Lecture 5: Asymptotic analysis of algorithmsLecture 5: Asymptotic analysis of algorithms
Lecture 5: Asymptotic analysis of algorithms
 
Searching Algorithms
Searching AlgorithmsSearching Algorithms
Searching Algorithms
 
UNIT I- Session 3.pptx
UNIT I- Session 3.pptxUNIT I- Session 3.pptx
UNIT I- Session 3.pptx
 
Looping statements
Looping statementsLooping statements
Looping statements
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
18103010 algorithm complexity (iterative)
18103010 algorithm complexity (iterative)18103010 algorithm complexity (iterative)
18103010 algorithm complexity (iterative)
 
2. Asymptotic Notations and Complexity Analysis.pptx
2. Asymptotic Notations and Complexity Analysis.pptx2. Asymptotic Notations and Complexity Analysis.pptx
2. Asymptotic Notations and Complexity Analysis.pptx
 
Ch1. Analysis of Algorithms.pdf
Ch1. Analysis of Algorithms.pdfCh1. Analysis of Algorithms.pdf
Ch1. Analysis of Algorithms.pdf
 
Python if_else_loop_Control_Flow_Statement
Python if_else_loop_Control_Flow_StatementPython if_else_loop_Control_Flow_Statement
Python if_else_loop_Control_Flow_Statement
 
Operators loops conditional and statements
Operators loops conditional and statementsOperators loops conditional and statements
Operators loops conditional and statements
 
Complexity analysis in Algorithms
Complexity analysis in AlgorithmsComplexity analysis in Algorithms
Complexity analysis in Algorithms
 
While loop
While loopWhile loop
While loop
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity Calculation
 
Analysis and Algorithms: basic Introduction
Analysis and Algorithms: basic IntroductionAnalysis and Algorithms: basic Introduction
Analysis and Algorithms: basic Introduction
 
Asymptotic analysis of algorithms.pptx
Asymptotic analysis of algorithms.pptxAsymptotic analysis of algorithms.pptx
Asymptotic analysis of algorithms.pptx
 
Time_Complexity.pptx
Time_Complexity.pptxTime_Complexity.pptx
Time_Complexity.pptx
 

Recently uploaded

WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfryanfarris8
 
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 

Recently uploaded (20)

WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid Environments
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
 
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 

Step Count Method for Time Complexity Analysis.pptx

  • 1. Step Count Method for Time Complexity Analysis
  • 2. What is Time Complexity? • Time Complexity is the amount of time taken by the algorithm to run. It measures the time taken to execute each statement of code in an algorithm. Time Complexity can be calculated by using : • Step Count Method with Asymptotic Notation.
  • 3. What is Step Count Method? • The step count method is one of the methods to analyze the Time complexity of an algorithm. In this method, we count the number of times each instruction is executed. Based on that we will calculate the Time Complexity. • The step Count method is also called as Frequency Count method.
  • 4. Let us discuss step count for different statements: • 1. Comments: • Comments are used for giving extra meaning to the program. They are not executed during the execution. Comments are ignored during execution. • Therefore the number of times that a comment executes is 0.
  • 5. (Cont..) • 2. Conditional statements: • Conditional statements check the condition and if the condition is correct then the conditional subpart will be executed. So the execution of conditional statements happens only once. The compiler will execute the conditional statements to check whether the condition is correct or not so it will be executed one time. • In if-else statements the if statement is executed one time but the else statement will be executed zero or one time because if the “if” statement is executed then the else statement will not execute. • In switch case statements the starting switch(condition) statement will be executed one time but the inner case statements will execute if none of the previous case statements are executed. • In nested if and if else ladder statements also the initial if statement is executed at least once but inner statements will be executed based on the previous statements’ execution.
  • 6. (Cont..) • 3. Loop statements: • Loop statements are iterative statements. They are executed one or more times based on a given condition. • A typical for(i = 0; i ≤ n; i++) statement will be executed “n+1” times for the first n times the condition is satisfied and the inner loop will be executed and for the (n+1)th time the condition is failed and the loop terminates. • While: The statement is executed until the given condition is satisfied. • Do while: The statement will repeat until the given condition is satisfied. The do-while statement will execute at least once because for the first time it will not check the condition.
  • 7. (Cont..) • 4. Functions: • Functions are executed based on the number of times they get called. If they get called n times they will be executed n times. If they are not called at least once then they will not be executed. Other statements like BEGIN, END and goto statements will be executed one time.
  • 8. Illustration of Step Count Method: • Analysis of Linear Search algorithm • Let us consider a Linear Search Algorithm. • Linearsearch(arr, n, key) • { • i = 0; • for(i = 0; i < n; i++) • { • if(arr[i] == key) • { • printf(“Found”); • } • }
  • 9. (Cont..) • Where, • i = 0, is an initialization statement and takes O(1) times. • for(i = 0;i < n ; i++), is a loop and it takes O(n+1) times . • if(arr[i] == key), is a conditional statement and takes O(1) times. • printf(“Found”), is a function and that takes O(0)/O(1) times. • Therefore Total Number of times it is executed is n + 4 times. As we ignore lower exponents in time complexity total time became O(n). • Time complexity: O(n). Auxiliary Space: O(1)
  • 11. Sequential Statements • If we have statements with basic operations like comparisons, assignments, reading a variable. We can assume they take constant time each O(1). • statement1; • statement2; • ... • statementN; Example: • function squareSum(a, b, c) { • const sa = a * a; • const sb = b * b; • const sc = c * c; • const sum = sa + sb + sc; • return sum; • }
  • 12. Conditional Statements • if (isValid) { • statement1; • statement2; • } else { • statement3; • } • we can express the time complexity as O(n log n)
  • 13. Loop Statements Linear Time Loops • for (let i = 0; i < array.length; i++) • { • statement1; • statement2; • } • All loops that grow proportionally to the input size have a linear time complexity O(n) Constant-Time Loops • for (let i = 0; i < 4; i++) { • statement1; • statement2; • } • That code is O(1) because it no longer depends on the input size.
  • 14. Logarithmic Time Loops • Consider the following code, where we divide an array in half on each iteration (binary search) • function fn1(array, target, low = 0, high = array.length - 1) { • let mid; • while ( low <= high ) { • mid = ( low + high ) / 2; • if ( target < array[mid] ) • high = mid - 1; • else if ( target > array[mid] ) • low = mid + 1; • else break; • } • return mid; • } • Time complexity: O(log(n))
  • 15. Nested loops statements • for (let i = 0; i < n; i++) { • statement1; • for (let j = 0; j < m; j++) { • statement2; • statement3; • } • } • Time Complexity: O(n^2)
  • 16. Time Complexity Description O(1) It is called constant complexity when the algorithm takes the same amount of time regardless of the input size n. O(logn) It's called logarithmic complexity when the algorithm takes space proportional to the log of the input size n. O(n) It's called linear complexity when an algorithm takes space directly proportional to the input size n. O(nlogn) It's called log-linear complexity when the space complexity of an algorithm grows proportionally to the input size n and a logarithmic factor log(). O(n^2) It's called polynomial complexity when the space complexity grows proportionally to the square of the input size n. O(2^n) It's called exponential time complexity when an algorithm's growth doubles with each addition to the input dataset.
  • 17. Order of Time Complexity