SlideShare a Scribd company logo
Time complexity:
Worst Case Scenario Average Case
Scenario
Best Case Scenario
Accessing an
element
O(1) O(1) O(1)
Updating an
element
O(1) O(1) O(1)
Deleting an
element
O(n) O(n) O(1)
Inserting an
element
O(n) O(n) O(1)
Searching for
an element
O(n) O(n) O(1)
Arrays
(Space-Time complexity)
Algorithm complexity:
Time Complexity Space
Complexity
Worst Case Average Case Best Case
Quicksort O(n2
) O(n log(n)) O(n log(n)) O(log(n))
Mergesort O(n log(n)) O(n log(n)) O(n log(n)) O(n)
Heapsort O(n log(n)) O(n log(n)) O(n log(n)) O(1)
Bubble Sort O(n2
) O(n2
) O(n) O(1)
Insertion Sort O(n2
) O(n2
) O(n) O(1)
Selection Sort O(n2
) O(n2
) O(n2
) O(1)
Binary Search O(log(n)) O(log(n)) O(1) O(1)
Linear Search O(n) O(n) O(1) O(1)
Time complexity:
Strings
(Space-time complexity)
Algorithm complexity:
Time Complexity Space
Complexity
Worst Case Average
Case
Best Case
Radix sort
(m = longest string length)
O(n * m) O(n * m) O(n * m) O(n + m)
Naive string search
(m = size of pattern)
O(m*(n-m+1)) O(n * m) O(n) O(1)
Knuth-Morris-Pratt search O(m + n) O(n) O(n) O(m)
Boyer-Moore string search O(n * m) O(n) O(n/m) O(m)
Rubin-Karp Algorithm O(m*(n-m+1)) O(n + m) O(m) O(m)
Worst Case
Scenario
Average Case
Scenario
Best Case Scenario
Accessing O(1) O(1) O(1)
Deleting O(n) O(n) O(1)
Inserting O(n) O(n) O(1)
Searching
(n = string length
m = pattern length)
O(n * m) O(n) O(1)
Slicing
(n = string length)
O(n) O(n) O(n)
Concatenating
(n, m = string lengths)
O(n + m) O(n + m) O(n)
Comparison
(n = shorter string length)
O(n) O(n) O(n)
Inserting (Trie)
(m = key length)
O(m) O(m) O(1)
Searching (Trie)
(m = key length)
O(m) O(m) O(1)
Time complexity:
Stacks &
Queues
(Space-time complexity)
Algorithm Complexity:
Time Complexity Space
Complexity
Worst Case Average Case Best Case
Linear Search O(n) O(n) O(1) O(1)
Stack: LIFO (Last In First Out)
Queue: FIFO (First In First Out)
Worst Case
Scenario
Average Case
Scenario
Best Case Scenario
Delete (Stack) O(1) O(1) O(1)
Insert (Stack) O(1) O(1) O(1)
Search (Stack) O(n) O(n) O(1)
Peek/Top (Stack) O(1) O(1) O(1)
Delete (Queue) O(1) O(1) O(1)
Insert (Queue) O(1) O(1) O(1)
Search (Queue) O(n) O(n) O(1)
Time complexity:
Linked
Lists
(Space-time complexity)
Algorithm Complexity:
Time Complexity Space Complexity
Worst Case Average Case Best Case
Mergesort O(n log n) O(n log n) O(n log n) O(n)
Bubble Sort O(n²) O(n²) O(n) O(1)
Selection Sort O(n²) O(n²) O(n²) O(1)
Insertion Sort O(n²) O(n²) O(n) O(1)
Linear Search O(n) O(n) O(1) O(1)
Worst Case Scenario Average Case Scenario Best Case Scenario
Accessing O(n) O(n) O(1)
Deleting
(after search)
O(1) O(1) O(1)
Inserting
(after search)
O(1) O(1) O(1)
Searching O(n) O(n) O(1)
Traversing O(n) O(n) O(n)
Access (Skip List) O(n) O(log n) O(log n)
Delete (Skip List) O(n) O(log n) O(log n)
Insert (Skip List) O(n) O(log n) O(log n)
Search (Skip List) O(n) O(log n) O(log n)
Time complexity:
Trees
(Space-time complexity)
Algorithm Complexity:
Time Complexity Space
Complexity
Worst Case Average
Case
Best Case
Depth-First Search
(In-order, pre-order, and
post-order traversal)
O(n) O(n) O(n) O(n)
Breadth-First Search
(Level-order traversal)
O(n) O(n) O(n) O(n)
Tree Sort O(n2
) O(n log n) O(n log n) O(n)
Splaysort O(n log n) O(n log n) O(n) O(n)
Cartesian Tree Sort O(n log n) O(n log n) O(n) O(n)
Worst Case
Scenario
Average Case
Scenario
Best Case
Scenario
Binary Search
Tree,
Cartesian Tree,
KD Tree
Delete O(n) O(log n) O(log n)
Insert O(n) O(log n) O(log n)
Search O(n) O(log n) O(log n)
B-Tree,
Red-Black Tree,
Splay Tree,
AVL Tree
Delete O(log n) O(log n) O(log n)
Insert O(log n) O(log n) O(log n)
Search O(log n) O(log n) O(log n)
Traversal O(n) O(n) O(n)
Time Complexity:
Graphs
(Space-time complexity)
Algorithm Complexity:
Time Complexity Space Complexity
Worst Case Average
Case
Best Case
Breadth-First Search O(V+E) O(V+E) O(V+E) O(V)
Depth-First Search O(V+E) O(V+E) O(V+E) O(V)
A* Search O(E) O(E) O(E) O(V)
Dijkstra’s algorithm O(V2
) O(E * log(V)) O(E * log(V)) O(V)
Floyd–Warshall O(V3
) O(V3
) O(V3
) O(V2
)
Worst Case
Scenario
Average Case
Scenario
Best Case
Scenario
Insert Vertex Adjacency List O(1) O(1) O(1)
Adjacency Matrix O(V2
) O(V2
) O(V2
)
Incidence Matrix O(V*E) O(V*E) O(V*E)
Remove Vertex Adjacency List O(E) O(E) O(E)
Adjacency Matrix O(V2
) O(V2
) O(V2
)
Incidence Matrix O(V*E) O(V*E) O(V*E)
Insert Edge Adjacency List O(1) O(1) O(1)
Adjacency Matrix O(1) O(1) O(1)
Incidence Matrix O(V*E) O(V*E) O(V*E)
Remove Edge Adjacency List O(V) O(V) O(V)
Adjacency Matrix O(1) O(1) O(1)
Incidence Matrix O(V*E) O(V*E) O(V*E)
Check if
Vertices
Adjacent
Adjacency List O(V) O(V) O(V)
Adjacency Matrix O(1) O(1) O(1)
Incidence Matrix O(E) O(E) O(E)
Time complexity:
Maps
(Space-time complexity) Algorithm Complexity:
Time Complexity Space
Complexity
Worst Case Average Case Best Case
Bucket Sort
(k = buckets)
O(n2
) O(n + k) O(n + k) O(n)
Insertion Sort O(n2
) O(n2
) O(n) O(1)
Selection Sort O(n2
) O(n2
) O(n2
) O(1)
Heapsort O(n log(n)) O(n log(n)) O(n log(n)) O(1)
Hash-based Search O(n) O(1) O(1) O(1)
Binary Search O(log(n)) O(log(n)) O(1) O(1)
Linear Search O(n) O(n) O(1) O(1)
Rabin-Karp Algorithm O(m*(n-m+1)) O(n + m) O(m) O(m)
Worst Case
Scenario
Average Case
Scenario
Best Case Scenario
Updating an element O(n) O(1) O(1)
Inserting an element O(n) O(1) O(1)
Deleting an element O(n) O(1) O(1)
Searching for an
element
O(n) O(1) O(1)
Insert (TreeMap) O(log n) O(log n) O(1)
Delete (TreeMap) O(log n) O(log n) O(1)
Search (TreeMap) O(log n) O(log n) O(1)
Time complexity:
Heaps
(Space-time complexity)
Algorithm Complexity:
Time Complexity Space
Complexity
Worst Case Average
Case
Best Case
Heapsort O(n log(n)) O(n log(n)) O(n log(n)) O(1)
Smoothsort O(n log(n)) O(n log(n)) O(n) O(n)
Quick select O(n2) O(n) O(n) O(1)
Linear Search O(n) O(n) O(1) O(1)
Dijkstra’s shortest
path
O(V2
) O(E * log(V)) O(E * log(V)) O(V)
Worst Case
Scenario
Average Case
Scenario
Best Case Scenario
Insert O(log n) O(logn) O(1)
Delete O(log n) O(log n) O(1)
Find min/max O(1) O(1) O(1)
Search O(n) O(n) O(1)
Insert
(Fibonacci/Binomial)
O(log n) O(1) O(1)
Increase/Decrease key O(log n) O(log n) O(1)
Extract min/max O(log n) O(log n) O(log n)

More Related Content

Similar to AlgoComplexcity.pdf

SPSF04 - Euler and Runge-Kutta Methods
SPSF04 - Euler and Runge-Kutta MethodsSPSF04 - Euler and Runge-Kutta Methods
SPSF04 - Euler and Runge-Kutta Methods
Syeilendra Pramuditya
 
09 - 27 Jan - Recursion Part 1
09 - 27 Jan - Recursion Part 109 - 27 Jan - Recursion Part 1
09 - 27 Jan - Recursion Part 1
Neeldhara Misra
 
Logic and Reasoning in the Semantic Web (part II –OWL)
Logic and Reasoning in the Semantic Web (part II –OWL)Logic and Reasoning in the Semantic Web (part II –OWL)
Logic and Reasoning in the Semantic Web (part II –OWL)
Fulvio Corno
 
Digital Signal Processing and the z-transform
Digital Signal Processing and the  z-transformDigital Signal Processing and the  z-transform
Digital Signal Processing and the z-transform
RowenaDulay1
 
dsp dsp by Dr. k Udaya kumar power point
dsp dsp by Dr. k Udaya kumar power pointdsp dsp by Dr. k Udaya kumar power point
dsp dsp by Dr. k Udaya kumar power point
AnujKumar734472
 
First Order Active RC Sections
First Order Active RC SectionsFirst Order Active RC Sections
First Order Active RC Sections
Hoopeer Hoopeer
 
Unit2
Unit2Unit2
5.pdf
5.pdf5.pdf
Lec10
Lec10Lec10
Mid term solution
Mid term solutionMid term solution
Mid term solution
Gopi Saiteja
 
Location of Zeros of Polynomials
Location of Zeros of PolynomialsLocation of Zeros of Polynomials
Location of Zeros of Polynomials
ijceronline
 
Maapr3
Maapr3Maapr3
Maapr3
FNian
 
Linear response theory and TDDFT
Linear response theory and TDDFT Linear response theory and TDDFT
Linear response theory and TDDFT
Claudio Attaccalite
 
Quicksort analysis
Quicksort analysisQuicksort analysis
Quicksort analysis
Premjeet Roy
 
shell and merge sort
shell and merge sortshell and merge sort
shell and merge sort
i i
 
Metodo Monte Carlo -Wang Landau
Metodo Monte Carlo -Wang LandauMetodo Monte Carlo -Wang Landau
Metodo Monte Carlo -Wang Landau
angely alcendra
 
Polynomial Matrix Decompositions
Polynomial Matrix DecompositionsPolynomial Matrix Decompositions
Polynomial Matrix Decompositions
Förderverein Technische Fakultät
 
19 algorithms-and-complexity-110627100203-phpapp02
19 algorithms-and-complexity-110627100203-phpapp0219 algorithms-and-complexity-110627100203-phpapp02
19 algorithms-and-complexity-110627100203-phpapp02
Muhammad Aslam
 
Deep Learning: Recurrent Neural Network (Chapter 10)
Deep Learning: Recurrent Neural Network (Chapter 10) Deep Learning: Recurrent Neural Network (Chapter 10)
Deep Learning: Recurrent Neural Network (Chapter 10)
Larry Guo
 
Operational Transformation in Real-Time Group Editors: Issues, Algorithms, an...
Operational Transformation in Real-Time Group Editors: Issues, Algorithms, an...Operational Transformation in Real-Time Group Editors: Issues, Algorithms, an...
Operational Transformation in Real-Time Group Editors: Issues, Algorithms, an...
g Edwards
 

Similar to AlgoComplexcity.pdf (20)

SPSF04 - Euler and Runge-Kutta Methods
SPSF04 - Euler and Runge-Kutta MethodsSPSF04 - Euler and Runge-Kutta Methods
SPSF04 - Euler and Runge-Kutta Methods
 
09 - 27 Jan - Recursion Part 1
09 - 27 Jan - Recursion Part 109 - 27 Jan - Recursion Part 1
09 - 27 Jan - Recursion Part 1
 
Logic and Reasoning in the Semantic Web (part II –OWL)
Logic and Reasoning in the Semantic Web (part II –OWL)Logic and Reasoning in the Semantic Web (part II –OWL)
Logic and Reasoning in the Semantic Web (part II –OWL)
 
Digital Signal Processing and the z-transform
Digital Signal Processing and the  z-transformDigital Signal Processing and the  z-transform
Digital Signal Processing and the z-transform
 
dsp dsp by Dr. k Udaya kumar power point
dsp dsp by Dr. k Udaya kumar power pointdsp dsp by Dr. k Udaya kumar power point
dsp dsp by Dr. k Udaya kumar power point
 
First Order Active RC Sections
First Order Active RC SectionsFirst Order Active RC Sections
First Order Active RC Sections
 
Unit2
Unit2Unit2
Unit2
 
5.pdf
5.pdf5.pdf
5.pdf
 
Lec10
Lec10Lec10
Lec10
 
Mid term solution
Mid term solutionMid term solution
Mid term solution
 
Location of Zeros of Polynomials
Location of Zeros of PolynomialsLocation of Zeros of Polynomials
Location of Zeros of Polynomials
 
Maapr3
Maapr3Maapr3
Maapr3
 
Linear response theory and TDDFT
Linear response theory and TDDFT Linear response theory and TDDFT
Linear response theory and TDDFT
 
Quicksort analysis
Quicksort analysisQuicksort analysis
Quicksort analysis
 
shell and merge sort
shell and merge sortshell and merge sort
shell and merge sort
 
Metodo Monte Carlo -Wang Landau
Metodo Monte Carlo -Wang LandauMetodo Monte Carlo -Wang Landau
Metodo Monte Carlo -Wang Landau
 
Polynomial Matrix Decompositions
Polynomial Matrix DecompositionsPolynomial Matrix Decompositions
Polynomial Matrix Decompositions
 
19 algorithms-and-complexity-110627100203-phpapp02
19 algorithms-and-complexity-110627100203-phpapp0219 algorithms-and-complexity-110627100203-phpapp02
19 algorithms-and-complexity-110627100203-phpapp02
 
Deep Learning: Recurrent Neural Network (Chapter 10)
Deep Learning: Recurrent Neural Network (Chapter 10) Deep Learning: Recurrent Neural Network (Chapter 10)
Deep Learning: Recurrent Neural Network (Chapter 10)
 
Operational Transformation in Real-Time Group Editors: Issues, Algorithms, an...
Operational Transformation in Real-Time Group Editors: Issues, Algorithms, an...Operational Transformation in Real-Time Group Editors: Issues, Algorithms, an...
Operational Transformation in Real-Time Group Editors: Issues, Algorithms, an...
 

Recently uploaded

Build applications with generative AI on Google Cloud
Build applications with generative AI on Google CloudBuild applications with generative AI on Google Cloud
Build applications with generative AI on Google Cloud
Márton Kodok
 
一比一原版雷丁大学毕业证(UoR毕业证书)学历如何办理
一比一原版雷丁大学毕业证(UoR毕业证书)学历如何办理一比一原版雷丁大学毕业证(UoR毕业证书)学历如何办理
一比一原版雷丁大学毕业证(UoR毕业证书)学历如何办理
mbawufebxi
 
Telemetry Solution for Gaming (AWS Summit'24)
Telemetry Solution for Gaming (AWS Summit'24)Telemetry Solution for Gaming (AWS Summit'24)
Telemetry Solution for Gaming (AWS Summit'24)
GeorgiiSteshenko
 
Template xxxxxxxx ssssssssssss Sertifikat.pptx
Template xxxxxxxx ssssssssssss Sertifikat.pptxTemplate xxxxxxxx ssssssssssss Sertifikat.pptx
Template xxxxxxxx ssssssssssss Sertifikat.pptx
TeukuEriSyahputra
 
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
z6osjkqvd
 
reading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdf
reading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdfreading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdf
reading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdf
perranet1
 
Sample Devops SRE Product Companies .pdf
Sample Devops SRE  Product Companies .pdfSample Devops SRE  Product Companies .pdf
Sample Devops SRE Product Companies .pdf
Vineet
 
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
oaxefes
 
一比一原版莱斯大学毕业证(rice毕业证)如何办理
一比一原版莱斯大学毕业证(rice毕业证)如何办理一比一原版莱斯大学毕业证(rice毕业证)如何办理
一比一原版莱斯大学毕业证(rice毕业证)如何办理
zsafxbf
 
Module 1 ppt BIG DATA ANALYTICS_NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS_NOTES FOR MCAModule 1 ppt BIG DATA ANALYTICS_NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS_NOTES FOR MCA
yuvarajkumar334
 
一比一原版悉尼大学毕业证如何办理
一比一原版悉尼大学毕业证如何办理一比一原版悉尼大学毕业证如何办理
一比一原版悉尼大学毕业证如何办理
keesa2
 
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
nyvan3
 
Drownings spike from May to August in children
Drownings spike from May to August in childrenDrownings spike from May to August in children
Drownings spike from May to August in children
Bisnar Chase Personal Injury Attorneys
 
ML-PPT-UNIT-2 Generative Classifiers Discriminative Classifiers
ML-PPT-UNIT-2 Generative Classifiers Discriminative ClassifiersML-PPT-UNIT-2 Generative Classifiers Discriminative Classifiers
ML-PPT-UNIT-2 Generative Classifiers Discriminative Classifiers
MastanaihnaiduYasam
 
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理 原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
tzu5xla
 
Sid Sigma educational and problem solving power point- Six Sigma.ppt
Sid Sigma educational and problem solving power point- Six Sigma.pptSid Sigma educational and problem solving power point- Six Sigma.ppt
Sid Sigma educational and problem solving power point- Six Sigma.ppt
ArshadAyub49
 
Econ3060_Screen Time and Success_ final_GroupProject.pdf
Econ3060_Screen Time and Success_ final_GroupProject.pdfEcon3060_Screen Time and Success_ final_GroupProject.pdf
Econ3060_Screen Time and Success_ final_GroupProject.pdf
blueshagoo1
 
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
Vietnam Cotton & Spinning Association
 
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdfNamma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
22ad0301
 
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
lzdvtmy8
 

Recently uploaded (20)

Build applications with generative AI on Google Cloud
Build applications with generative AI on Google CloudBuild applications with generative AI on Google Cloud
Build applications with generative AI on Google Cloud
 
一比一原版雷丁大学毕业证(UoR毕业证书)学历如何办理
一比一原版雷丁大学毕业证(UoR毕业证书)学历如何办理一比一原版雷丁大学毕业证(UoR毕业证书)学历如何办理
一比一原版雷丁大学毕业证(UoR毕业证书)学历如何办理
 
Telemetry Solution for Gaming (AWS Summit'24)
Telemetry Solution for Gaming (AWS Summit'24)Telemetry Solution for Gaming (AWS Summit'24)
Telemetry Solution for Gaming (AWS Summit'24)
 
Template xxxxxxxx ssssssssssss Sertifikat.pptx
Template xxxxxxxx ssssssssssss Sertifikat.pptxTemplate xxxxxxxx ssssssssssss Sertifikat.pptx
Template xxxxxxxx ssssssssssss Sertifikat.pptx
 
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
 
reading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdf
reading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdfreading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdf
reading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdf
 
Sample Devops SRE Product Companies .pdf
Sample Devops SRE  Product Companies .pdfSample Devops SRE  Product Companies .pdf
Sample Devops SRE Product Companies .pdf
 
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
 
一比一原版莱斯大学毕业证(rice毕业证)如何办理
一比一原版莱斯大学毕业证(rice毕业证)如何办理一比一原版莱斯大学毕业证(rice毕业证)如何办理
一比一原版莱斯大学毕业证(rice毕业证)如何办理
 
Module 1 ppt BIG DATA ANALYTICS_NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS_NOTES FOR MCAModule 1 ppt BIG DATA ANALYTICS_NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS_NOTES FOR MCA
 
一比一原版悉尼大学毕业证如何办理
一比一原版悉尼大学毕业证如何办理一比一原版悉尼大学毕业证如何办理
一比一原版悉尼大学毕业证如何办理
 
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
 
Drownings spike from May to August in children
Drownings spike from May to August in childrenDrownings spike from May to August in children
Drownings spike from May to August in children
 
ML-PPT-UNIT-2 Generative Classifiers Discriminative Classifiers
ML-PPT-UNIT-2 Generative Classifiers Discriminative ClassifiersML-PPT-UNIT-2 Generative Classifiers Discriminative Classifiers
ML-PPT-UNIT-2 Generative Classifiers Discriminative Classifiers
 
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理 原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
原版一比一爱尔兰都柏林大学毕业证(UCD毕业证书)如何办理
 
Sid Sigma educational and problem solving power point- Six Sigma.ppt
Sid Sigma educational and problem solving power point- Six Sigma.pptSid Sigma educational and problem solving power point- Six Sigma.ppt
Sid Sigma educational and problem solving power point- Six Sigma.ppt
 
Econ3060_Screen Time and Success_ final_GroupProject.pdf
Econ3060_Screen Time and Success_ final_GroupProject.pdfEcon3060_Screen Time and Success_ final_GroupProject.pdf
Econ3060_Screen Time and Success_ final_GroupProject.pdf
 
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
 
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdfNamma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
 
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
一比一原版格里菲斯大学毕业证(Griffith毕业证书)学历如何办理
 

AlgoComplexcity.pdf

  • 1. Time complexity: Worst Case Scenario Average Case Scenario Best Case Scenario Accessing an element O(1) O(1) O(1) Updating an element O(1) O(1) O(1) Deleting an element O(n) O(n) O(1) Inserting an element O(n) O(n) O(1) Searching for an element O(n) O(n) O(1) Arrays (Space-Time complexity) Algorithm complexity: Time Complexity Space Complexity Worst Case Average Case Best Case Quicksort O(n2 ) O(n log(n)) O(n log(n)) O(log(n)) Mergesort O(n log(n)) O(n log(n)) O(n log(n)) O(n) Heapsort O(n log(n)) O(n log(n)) O(n log(n)) O(1) Bubble Sort O(n2 ) O(n2 ) O(n) O(1) Insertion Sort O(n2 ) O(n2 ) O(n) O(1) Selection Sort O(n2 ) O(n2 ) O(n2 ) O(1) Binary Search O(log(n)) O(log(n)) O(1) O(1) Linear Search O(n) O(n) O(1) O(1)
  • 2. Time complexity: Strings (Space-time complexity) Algorithm complexity: Time Complexity Space Complexity Worst Case Average Case Best Case Radix sort (m = longest string length) O(n * m) O(n * m) O(n * m) O(n + m) Naive string search (m = size of pattern) O(m*(n-m+1)) O(n * m) O(n) O(1) Knuth-Morris-Pratt search O(m + n) O(n) O(n) O(m) Boyer-Moore string search O(n * m) O(n) O(n/m) O(m) Rubin-Karp Algorithm O(m*(n-m+1)) O(n + m) O(m) O(m) Worst Case Scenario Average Case Scenario Best Case Scenario Accessing O(1) O(1) O(1) Deleting O(n) O(n) O(1) Inserting O(n) O(n) O(1) Searching (n = string length m = pattern length) O(n * m) O(n) O(1) Slicing (n = string length) O(n) O(n) O(n) Concatenating (n, m = string lengths) O(n + m) O(n + m) O(n) Comparison (n = shorter string length) O(n) O(n) O(n) Inserting (Trie) (m = key length) O(m) O(m) O(1) Searching (Trie) (m = key length) O(m) O(m) O(1)
  • 3. Time complexity: Stacks & Queues (Space-time complexity) Algorithm Complexity: Time Complexity Space Complexity Worst Case Average Case Best Case Linear Search O(n) O(n) O(1) O(1) Stack: LIFO (Last In First Out) Queue: FIFO (First In First Out) Worst Case Scenario Average Case Scenario Best Case Scenario Delete (Stack) O(1) O(1) O(1) Insert (Stack) O(1) O(1) O(1) Search (Stack) O(n) O(n) O(1) Peek/Top (Stack) O(1) O(1) O(1) Delete (Queue) O(1) O(1) O(1) Insert (Queue) O(1) O(1) O(1) Search (Queue) O(n) O(n) O(1)
  • 4. Time complexity: Linked Lists (Space-time complexity) Algorithm Complexity: Time Complexity Space Complexity Worst Case Average Case Best Case Mergesort O(n log n) O(n log n) O(n log n) O(n) Bubble Sort O(n²) O(n²) O(n) O(1) Selection Sort O(n²) O(n²) O(n²) O(1) Insertion Sort O(n²) O(n²) O(n) O(1) Linear Search O(n) O(n) O(1) O(1) Worst Case Scenario Average Case Scenario Best Case Scenario Accessing O(n) O(n) O(1) Deleting (after search) O(1) O(1) O(1) Inserting (after search) O(1) O(1) O(1) Searching O(n) O(n) O(1) Traversing O(n) O(n) O(n) Access (Skip List) O(n) O(log n) O(log n) Delete (Skip List) O(n) O(log n) O(log n) Insert (Skip List) O(n) O(log n) O(log n) Search (Skip List) O(n) O(log n) O(log n)
  • 5. Time complexity: Trees (Space-time complexity) Algorithm Complexity: Time Complexity Space Complexity Worst Case Average Case Best Case Depth-First Search (In-order, pre-order, and post-order traversal) O(n) O(n) O(n) O(n) Breadth-First Search (Level-order traversal) O(n) O(n) O(n) O(n) Tree Sort O(n2 ) O(n log n) O(n log n) O(n) Splaysort O(n log n) O(n log n) O(n) O(n) Cartesian Tree Sort O(n log n) O(n log n) O(n) O(n) Worst Case Scenario Average Case Scenario Best Case Scenario Binary Search Tree, Cartesian Tree, KD Tree Delete O(n) O(log n) O(log n) Insert O(n) O(log n) O(log n) Search O(n) O(log n) O(log n) B-Tree, Red-Black Tree, Splay Tree, AVL Tree Delete O(log n) O(log n) O(log n) Insert O(log n) O(log n) O(log n) Search O(log n) O(log n) O(log n) Traversal O(n) O(n) O(n)
  • 6. Time Complexity: Graphs (Space-time complexity) Algorithm Complexity: Time Complexity Space Complexity Worst Case Average Case Best Case Breadth-First Search O(V+E) O(V+E) O(V+E) O(V) Depth-First Search O(V+E) O(V+E) O(V+E) O(V) A* Search O(E) O(E) O(E) O(V) Dijkstra’s algorithm O(V2 ) O(E * log(V)) O(E * log(V)) O(V) Floyd–Warshall O(V3 ) O(V3 ) O(V3 ) O(V2 ) Worst Case Scenario Average Case Scenario Best Case Scenario Insert Vertex Adjacency List O(1) O(1) O(1) Adjacency Matrix O(V2 ) O(V2 ) O(V2 ) Incidence Matrix O(V*E) O(V*E) O(V*E) Remove Vertex Adjacency List O(E) O(E) O(E) Adjacency Matrix O(V2 ) O(V2 ) O(V2 ) Incidence Matrix O(V*E) O(V*E) O(V*E) Insert Edge Adjacency List O(1) O(1) O(1) Adjacency Matrix O(1) O(1) O(1) Incidence Matrix O(V*E) O(V*E) O(V*E) Remove Edge Adjacency List O(V) O(V) O(V) Adjacency Matrix O(1) O(1) O(1) Incidence Matrix O(V*E) O(V*E) O(V*E) Check if Vertices Adjacent Adjacency List O(V) O(V) O(V) Adjacency Matrix O(1) O(1) O(1) Incidence Matrix O(E) O(E) O(E)
  • 7. Time complexity: Maps (Space-time complexity) Algorithm Complexity: Time Complexity Space Complexity Worst Case Average Case Best Case Bucket Sort (k = buckets) O(n2 ) O(n + k) O(n + k) O(n) Insertion Sort O(n2 ) O(n2 ) O(n) O(1) Selection Sort O(n2 ) O(n2 ) O(n2 ) O(1) Heapsort O(n log(n)) O(n log(n)) O(n log(n)) O(1) Hash-based Search O(n) O(1) O(1) O(1) Binary Search O(log(n)) O(log(n)) O(1) O(1) Linear Search O(n) O(n) O(1) O(1) Rabin-Karp Algorithm O(m*(n-m+1)) O(n + m) O(m) O(m) Worst Case Scenario Average Case Scenario Best Case Scenario Updating an element O(n) O(1) O(1) Inserting an element O(n) O(1) O(1) Deleting an element O(n) O(1) O(1) Searching for an element O(n) O(1) O(1) Insert (TreeMap) O(log n) O(log n) O(1) Delete (TreeMap) O(log n) O(log n) O(1) Search (TreeMap) O(log n) O(log n) O(1)
  • 8. Time complexity: Heaps (Space-time complexity) Algorithm Complexity: Time Complexity Space Complexity Worst Case Average Case Best Case Heapsort O(n log(n)) O(n log(n)) O(n log(n)) O(1) Smoothsort O(n log(n)) O(n log(n)) O(n) O(n) Quick select O(n2) O(n) O(n) O(1) Linear Search O(n) O(n) O(1) O(1) Dijkstra’s shortest path O(V2 ) O(E * log(V)) O(E * log(V)) O(V) Worst Case Scenario Average Case Scenario Best Case Scenario Insert O(log n) O(logn) O(1) Delete O(log n) O(log n) O(1) Find min/max O(1) O(1) O(1) Search O(n) O(n) O(1) Insert (Fibonacci/Binomial) O(log n) O(1) O(1) Increase/Decrease key O(log n) O(log n) O(1) Extract min/max O(log n) O(log n) O(log n)