SlideShare a Scribd company logo
SANJIVANI K. B. P. POLYTECHNIC,
KOPARGAON
With NBA ACCREDIATED programs , Approved by AICTE, New Delhi,
Recognized by Govt. of Maharashtra, Affiliated to Maharashtra State Board of
Technical Education, Mumbai, ISO 9001:2015 Certified Institute
Name of Faculty: Prof. Vaibhav A. Parjane
1
Topic to be Covered
Time Complexity
2
Sanjivani K. B. P. Polytechnic, Kopargaon Department of Computer Technology Prof. Vaibhav A. Parjane
Time Complexity :
1. Time complexity is the total time taken by the algorithm
to perform the intended task.
2. It is also known as frequency count.
3. Eg: consider the FOR LOOP
For ( i=0 ; i<n ; i++ )
Atleast once (1) + (n+1) + n
= 1 + (n+1) +n
= 2n + 2
true
false
3
Sanjivani K. B. P. Polytechnic, Kopargaon Department of Computer Technology Prof. Vaibhav A. Parjane
Time Complexity:
Ex: Consider the following algorithm to add two
numbers
𝐴𝑙𝑔𝑜_𝑎𝑑𝑑 (𝑎, 𝑏)
𝑺𝒕𝒆𝒑 𝟏. 𝑪 = 𝒂 + 𝒃;
𝑺𝒕𝒆𝒑 𝟐. 𝒓𝒆𝒕𝒖𝒓𝒏 𝑪;
Here, algorithm has only two simple statements so the
complexity of this algorithm is 2
4
Sanjivani K. B. P. Polytechnic, Kopargaon Department of Computer Technology Prof. Vaibhav A. Parjane
Example
void main ( )
{
int i , n , sum , x;
sum = 0;
printf(“Enter number of elements : ”);
scanf(“ %d” , &n);
for (i=0 ; i<n ; i++)
{
scanf(“ %d” , &x);
sum= sum + x;
}
printf(“sum = % d” , sum );
}
1. In the for loop, the condition
(i<n) will be executed (n+1)
times , and not ‘n’ times.
2. For all values of ‘i’ between 1
and n , the condition (i<n)
will evaluate to true and
when ‘i’ becomes (n+1) , the
condition (i<n) will evaluate
to false.
3. Thus the above instruction
will be executed (n+1) times.
5
Sanjivani K. B. P. Polytechnic, Kopargaon Department of Computer Technology Prof. Vaibhav A. Parjane
Calculation of computation time
Statement Frequency
sum = 0 1
printf(“Enter number of elements : ”); 1
scanf(“ %d” , &n); 1
for (i=0 1
i<n n + 1
i++ n
scanf(“ %d” , &x); n
sum= sum + x; n
printf(“sum = % d” , sum ); 1
=1 + 1 + 1 +1 + (n+1) + n + n + n + 1 =(6+4n)
6
Sanjivani K. B. P. Polytechnic, Kopargaon Department of Computer Technology Prof. Vaibhav A. Parjane
Example :
i=1;
while (i< = n)
{
x = x +1 ;
i = i + 1;
}
Statement Frequency
i=1; 1
while (i< = n) n +1
x = x +1 ; n
i = i + 1; n
=1 + (n+1) + n + n =(2+3n)
7
Sanjivani K. B. P. Polytechnic, Kopargaon Department of Computer Technology Prof. Vaibhav A. Parjane

More Related Content

PPTX
Ch-2 final exam documet compler design elements
PDF
Complete Lab 123456789123456789123456789
PDF
Lab program 1234567891234567891234567891
PDF
lab.123456789123456789123456789123456789
 
PPT
04-Induction and Recursion.ppt ppt bai tap
PDF
What is Algorithm - An Overview
PDF
008. PROGRAM EFFICIENCY computer science.pdf
PPTX
APSEC2020 Keynote
Ch-2 final exam documet compler design elements
Complete Lab 123456789123456789123456789
Lab program 1234567891234567891234567891
lab.123456789123456789123456789123456789
 
04-Induction and Recursion.ppt ppt bai tap
What is Algorithm - An Overview
008. PROGRAM EFFICIENCY computer science.pdf
APSEC2020 Keynote

Similar to unit 1 SIXTH.pptx Algorithm Complexity Time (20)

PDF
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
PDF
Operator Overloading Introduction and Concept of OV
PDF
Cp manual final
PDF
Ds practical file
PPTX
Mathematical Reasoning in Discrete Mathmatics.pptx
PPTX
Mathematical Reasoning in Discrete Mathmatics.pptx
PDF
Data Structure: Algorithm and analysis
DOCX
Let us C (by yashvant Kanetkar) chapter 3 Solution
PDF
PDF
Sw metrics for regression testing
PPTX
The Complexity Of Primality Testing
PPTX
Lecture 7.pptx
PPTX
Computational Complexity.pptx
PPT
UNIT-2-PPTS-DAA.ppt
PPTX
dynamic programming complete by Mumtaz Ali (03154103173)
PDF
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
PDF
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
PDF
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
PDF
Chapter 1_Sets. Operation sets, Principle of inclusion and exclusion etc.
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
Operator Overloading Introduction and Concept of OV
Cp manual final
Ds practical file
Mathematical Reasoning in Discrete Mathmatics.pptx
Mathematical Reasoning in Discrete Mathmatics.pptx
Data Structure: Algorithm and analysis
Let us C (by yashvant Kanetkar) chapter 3 Solution
Sw metrics for regression testing
The Complexity Of Primality Testing
Lecture 7.pptx
Computational Complexity.pptx
UNIT-2-PPTS-DAA.ppt
dynamic programming complete by Mumtaz Ali (03154103173)
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
Chapter 1_Sets. Operation sets, Principle of inclusion and exclusion etc.
Ad

More from Vaibhav Parjane (13)

PPTX
Advantages and disadvantages of algorithm.pptx
PPTX
Examples of Algorithms : Introduction to C.pptx
PPTX
Topic 1.1 Fundamentals of Algorithm.pptx
PPTX
Unit no 1(Fundamentals of Algorithm).pptx
PPTX
Unit 1(1).pptx Program Logic Development
PPTX
Unit No 2.pptx Basic s of C Programming
PPTX
Unit 2 Searching and Sorting Technique.pptx
PPTX
PPT.pptx Searching and Sorting Techniques
PPTX
unit 2 First.pptx Searching - Linear and Binary Search
PPTX
Operations on Data Structure- Several Operation performed on DS
PPTX
Classification of Data Structure -Linear and Non Linear
PPTX
Need of Data Structure & Abstract Data Type
PPTX
Introduction to data & Data Structure Definition
Advantages and disadvantages of algorithm.pptx
Examples of Algorithms : Introduction to C.pptx
Topic 1.1 Fundamentals of Algorithm.pptx
Unit no 1(Fundamentals of Algorithm).pptx
Unit 1(1).pptx Program Logic Development
Unit No 2.pptx Basic s of C Programming
Unit 2 Searching and Sorting Technique.pptx
PPT.pptx Searching and Sorting Techniques
unit 2 First.pptx Searching - Linear and Binary Search
Operations on Data Structure- Several Operation performed on DS
Classification of Data Structure -Linear and Non Linear
Need of Data Structure & Abstract Data Type
Introduction to data & Data Structure Definition
Ad

Recently uploaded (20)

PPTX
web development for engineering and engineering
PPTX
Current and future trends in Computer Vision.pptx
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
Well-logging-methods_new................
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Safety Seminar civil to be ensured for safe working.
PPT
Mechanical Engineering MATERIALS Selection
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
UNIT 4 Total Quality Management .pptx
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
Sustainable Sites - Green Building Construction
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PPTX
Internet of Things (IOT) - A guide to understanding
web development for engineering and engineering
Current and future trends in Computer Vision.pptx
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Well-logging-methods_new................
Operating System & Kernel Study Guide-1 - converted.pdf
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Safety Seminar civil to be ensured for safe working.
Mechanical Engineering MATERIALS Selection
R24 SURVEYING LAB MANUAL for civil enggi
Foundation to blockchain - A guide to Blockchain Tech
CH1 Production IntroductoryConcepts.pptx
UNIT 4 Total Quality Management .pptx
Automation-in-Manufacturing-Chapter-Introduction.pdf
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Sustainable Sites - Green Building Construction
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
Internet of Things (IOT) - A guide to understanding

unit 1 SIXTH.pptx Algorithm Complexity Time

  • 1. SANJIVANI K. B. P. POLYTECHNIC, KOPARGAON With NBA ACCREDIATED programs , Approved by AICTE, New Delhi, Recognized by Govt. of Maharashtra, Affiliated to Maharashtra State Board of Technical Education, Mumbai, ISO 9001:2015 Certified Institute Name of Faculty: Prof. Vaibhav A. Parjane 1
  • 2. Topic to be Covered Time Complexity 2 Sanjivani K. B. P. Polytechnic, Kopargaon Department of Computer Technology Prof. Vaibhav A. Parjane
  • 3. Time Complexity : 1. Time complexity is the total time taken by the algorithm to perform the intended task. 2. It is also known as frequency count. 3. Eg: consider the FOR LOOP For ( i=0 ; i<n ; i++ ) Atleast once (1) + (n+1) + n = 1 + (n+1) +n = 2n + 2 true false 3 Sanjivani K. B. P. Polytechnic, Kopargaon Department of Computer Technology Prof. Vaibhav A. Parjane
  • 4. Time Complexity: Ex: Consider the following algorithm to add two numbers 𝐴𝑙𝑔𝑜_𝑎𝑑𝑑 (𝑎, 𝑏) 𝑺𝒕𝒆𝒑 𝟏. 𝑪 = 𝒂 + 𝒃; 𝑺𝒕𝒆𝒑 𝟐. 𝒓𝒆𝒕𝒖𝒓𝒏 𝑪; Here, algorithm has only two simple statements so the complexity of this algorithm is 2 4 Sanjivani K. B. P. Polytechnic, Kopargaon Department of Computer Technology Prof. Vaibhav A. Parjane
  • 5. Example void main ( ) { int i , n , sum , x; sum = 0; printf(“Enter number of elements : ”); scanf(“ %d” , &n); for (i=0 ; i<n ; i++) { scanf(“ %d” , &x); sum= sum + x; } printf(“sum = % d” , sum ); } 1. In the for loop, the condition (i<n) will be executed (n+1) times , and not ‘n’ times. 2. For all values of ‘i’ between 1 and n , the condition (i<n) will evaluate to true and when ‘i’ becomes (n+1) , the condition (i<n) will evaluate to false. 3. Thus the above instruction will be executed (n+1) times. 5 Sanjivani K. B. P. Polytechnic, Kopargaon Department of Computer Technology Prof. Vaibhav A. Parjane
  • 6. Calculation of computation time Statement Frequency sum = 0 1 printf(“Enter number of elements : ”); 1 scanf(“ %d” , &n); 1 for (i=0 1 i<n n + 1 i++ n scanf(“ %d” , &x); n sum= sum + x; n printf(“sum = % d” , sum ); 1 =1 + 1 + 1 +1 + (n+1) + n + n + n + 1 =(6+4n) 6 Sanjivani K. B. P. Polytechnic, Kopargaon Department of Computer Technology Prof. Vaibhav A. Parjane
  • 7. Example : i=1; while (i< = n) { x = x +1 ; i = i + 1; } Statement Frequency i=1; 1 while (i< = n) n +1 x = x +1 ; n i = i + 1; n =1 + (n+1) + n + n =(2+3n) 7 Sanjivani K. B. P. Polytechnic, Kopargaon Department of Computer Technology Prof. Vaibhav A. Parjane