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

Similar to unit 1 SIXTH.pptx Algorithm Complexity Time

Cp manual final
Cp manual finalCp manual final
Cp manual final
itprasad1237
 
Daa
DaaDaa
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
Ganesh Solanke
 
Ds practical file
Ds practical fileDs practical file
Ds practical file
Khushboo Pal
 
presentation_python_11_1569171345_375360.pptx
presentation_python_11_1569171345_375360.pptxpresentation_python_11_1569171345_375360.pptx
presentation_python_11_1569171345_375360.pptx
GAURAVRATHORE86
 
Mathematical Reasoning in Discrete Mathmatics.pptx
Mathematical Reasoning in Discrete Mathmatics.pptxMathematical Reasoning in Discrete Mathmatics.pptx
Mathematical Reasoning in Discrete Mathmatics.pptx
gbikorno
 
Mathematical Reasoning in Discrete Mathmatics.pptx
Mathematical Reasoning in Discrete Mathmatics.pptxMathematical Reasoning in Discrete Mathmatics.pptx
Mathematical Reasoning in Discrete Mathmatics.pptx
gbikorno
 
Data Structure: Algorithm and analysis
Data Structure: Algorithm and analysisData Structure: Algorithm and analysis
Data Structure: Algorithm and analysis
Dr. Rajdeep Chatterjee
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
Hazrat Bilal
 
Looping
LoopingLooping
Sw metrics for regression testing
Sw metrics for regression testingSw metrics for regression testing
Sw metrics for regression testing
Jyotsna Sharma
 
The Complexity Of Primality Testing
The Complexity Of Primality TestingThe Complexity Of Primality Testing
The Complexity Of Primality Testing
Mohammad Elsheikh
 
Lecture 7.pptx
Lecture 7.pptxLecture 7.pptx
Lecture 7.pptx
Arul Jothi Yuvaraja
 
Computational Complexity.pptx
Computational Complexity.pptxComputational Complexity.pptx
Computational Complexity.pptx
EnosSalar
 
UNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.pptUNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.ppt
GovindUpadhyay25
 
dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)
Mumtaz Ali
 
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu C and Data Structures JNTUH HyderabadSrinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu
 
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU HyderabadSrinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
Srinivas Reddy Amedapu
 
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
HIMANSHU .
 
C important questions
C important questionsC important questions
C important questions
JYOTI RANJAN PAL
 

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

Cp manual final
Cp manual finalCp manual final
Cp manual final
 
Daa
DaaDaa
Daa
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Ds practical file
Ds practical fileDs practical file
Ds practical file
 
presentation_python_11_1569171345_375360.pptx
presentation_python_11_1569171345_375360.pptxpresentation_python_11_1569171345_375360.pptx
presentation_python_11_1569171345_375360.pptx
 
Mathematical Reasoning in Discrete Mathmatics.pptx
Mathematical Reasoning in Discrete Mathmatics.pptxMathematical Reasoning in Discrete Mathmatics.pptx
Mathematical Reasoning in Discrete Mathmatics.pptx
 
Mathematical Reasoning in Discrete Mathmatics.pptx
Mathematical Reasoning in Discrete Mathmatics.pptxMathematical Reasoning in Discrete Mathmatics.pptx
Mathematical Reasoning in Discrete Mathmatics.pptx
 
Data Structure: Algorithm and analysis
Data Structure: Algorithm and analysisData Structure: Algorithm and analysis
Data Structure: Algorithm and analysis
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
 
Looping
LoopingLooping
Looping
 
Sw metrics for regression testing
Sw metrics for regression testingSw metrics for regression testing
Sw metrics for regression testing
 
The Complexity Of Primality Testing
The Complexity Of Primality TestingThe Complexity Of Primality Testing
The Complexity Of Primality Testing
 
Lecture 7.pptx
Lecture 7.pptxLecture 7.pptx
Lecture 7.pptx
 
Computational Complexity.pptx
Computational Complexity.pptxComputational Complexity.pptx
Computational Complexity.pptx
 
UNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.pptUNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.ppt
 
dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)
 
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu C and Data Structures JNTUH HyderabadSrinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
 
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU HyderabadSrinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
 
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
 
C important questions
C important questionsC important questions
C important questions
 

More from Vaibhav Parjane

Unit 2 Searching and Sorting Technique.pptx
Unit 2 Searching and Sorting Technique.pptxUnit 2 Searching and Sorting Technique.pptx
Unit 2 Searching and Sorting Technique.pptx
Vaibhav Parjane
 
PPT.pptx Searching and Sorting Techniques
PPT.pptx Searching and Sorting TechniquesPPT.pptx Searching and Sorting Techniques
PPT.pptx Searching and Sorting Techniques
Vaibhav Parjane
 
unit 2 First.pptx Searching - Linear and Binary Search
unit 2 First.pptx Searching - Linear and Binary Searchunit 2 First.pptx Searching - Linear and Binary Search
unit 2 First.pptx Searching - Linear and Binary Search
Vaibhav Parjane
 
Operations on Data Structure- Several Operation performed on DS
Operations on Data Structure- Several Operation performed on DSOperations on Data Structure- Several Operation performed on DS
Operations on Data Structure- Several Operation performed on DS
Vaibhav Parjane
 
Classification of Data Structure -Linear and Non Linear
Classification of Data Structure -Linear and Non LinearClassification of Data Structure -Linear and Non Linear
Classification of Data Structure -Linear and Non Linear
Vaibhav Parjane
 
Need of Data Structure & Abstract Data Type
Need of Data Structure & Abstract Data TypeNeed of Data Structure & Abstract Data Type
Need of Data Structure & Abstract Data Type
Vaibhav Parjane
 
Introduction to data & Data Structure Definition
Introduction to data & Data Structure DefinitionIntroduction to data & Data Structure Definition
Introduction to data & Data Structure Definition
Vaibhav Parjane
 

More from Vaibhav Parjane (7)

Unit 2 Searching and Sorting Technique.pptx
Unit 2 Searching and Sorting Technique.pptxUnit 2 Searching and Sorting Technique.pptx
Unit 2 Searching and Sorting Technique.pptx
 
PPT.pptx Searching and Sorting Techniques
PPT.pptx Searching and Sorting TechniquesPPT.pptx Searching and Sorting Techniques
PPT.pptx Searching and Sorting Techniques
 
unit 2 First.pptx Searching - Linear and Binary Search
unit 2 First.pptx Searching - Linear and Binary Searchunit 2 First.pptx Searching - Linear and Binary Search
unit 2 First.pptx Searching - Linear and Binary Search
 
Operations on Data Structure- Several Operation performed on DS
Operations on Data Structure- Several Operation performed on DSOperations on Data Structure- Several Operation performed on DS
Operations on Data Structure- Several Operation performed on DS
 
Classification of Data Structure -Linear and Non Linear
Classification of Data Structure -Linear and Non LinearClassification of Data Structure -Linear and Non Linear
Classification of Data Structure -Linear and Non Linear
 
Need of Data Structure & Abstract Data Type
Need of Data Structure & Abstract Data TypeNeed of Data Structure & Abstract Data Type
Need of Data Structure & Abstract Data Type
 
Introduction to data & Data Structure Definition
Introduction to data & Data Structure DefinitionIntroduction to data & Data Structure Definition
Introduction to data & Data Structure Definition
 

Recently uploaded

学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
171ticu
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
Anant Corporation
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
Introduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptxIntroduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptx
MiscAnnoy1
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
Gino153088
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
PKavitha10
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
john krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptxjohn krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptx
Madan Karki
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
TaghreedAltamimi
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
Prakhyath Rai
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
Las Vegas Warehouse
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
KrishnaveniKrishnara1
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
Mahmoud Morsy
 

Recently uploaded (20)

学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
Introduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptxIntroduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptx
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
john krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptxjohn krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptx
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
 

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