SlideShare a Scribd company logo
What is the runtime complexity of Adam's famous string splitter code? Hint: Make sure to look
into the source code for string.find() in the C++ std library. I’ve included that code (downloaded
from GNU). static vector ring text string delimiter vector ring pieces int location text, (delimiter);
inte start 0; //while we find something interesting while location string DRos)f build substring
string piece text substr (start location start); (piece start location 1 //find again location ext find
deli miter start); string piece text substr (start location start); pieseswRush bask (piece return
pieces;
Solution
Assumption is we have text length as N and we have N-1 delimeters in that text.
text.find() -->Takes O(n) time in the worst case to find the delimeter.
vectorpieces; -->O(1)
int location = text.find();delimeter-->At max O(n)
while(location!=string.pos()){ . -> Runs N times
string piece = text.substr(start,location-start); -->At max takes O(N) [Copying that many
characters]*N times for while loop
start = location+1; -->O(1)
location = text.find(delimeter,start);-->At Max O(N) * N times for while loop
So While loop will run N time as we have N-1 delmieters and each time finding substr() and
find() on an average will take O(n). So overall time complexity is O(N2)
}
Thanks, let me know if there is any concern.

More Related Content

Similar to What is the runtime complexity of Adams famous string splitter cod.pdf

Python workshop intro_string (1)
Python workshop intro_string (1)Python workshop intro_string (1)
Python workshop intro_string (1)
Karamjit Kaur
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumar
Sujith Kumar
 
Lec18
Lec18Lec18
Rust - Fernando Borretti
Rust - Fernando BorrettiRust - Fernando Borretti
Rust - Fernando Borretti
Tryolabs
 
Programming with Python
Programming with PythonProgramming with Python
Programming with Python
Rasan Samarasinghe
 
Rust vs C++
Rust vs C++Rust vs C++
Rust vs C++
corehard_by
 
Kotlin coroutines and spring framework
Kotlin coroutines and spring frameworkKotlin coroutines and spring framework
Kotlin coroutines and spring framework
Sunghyouk Bae
 
C language sample test
C language sample testC language sample test
C language sample test
Sompal Duhan
 
Common mistakes in C programming
Common mistakes in C programmingCommon mistakes in C programming
Common mistakes in C programming
Larion
 
Deduplication on large amounts of code
Deduplication on large amounts of codeDeduplication on large amounts of code
Deduplication on large amounts of code
source{d}
 
Strings1
Strings1Strings1
Strings1
Michael Gordon
 
Huffman Code Decoding
Huffman Code DecodingHuffman Code Decoding
Huffman Code Decoding
Rex Yuan
 
Thnad's Revenge
Thnad's RevengeThnad's Revenge
Thnad's Revenge
Erin Dees
 
Ruby Supercomputing - Using The GPU For Massive Performance Speedup v1.1
Ruby Supercomputing - Using The GPU For Massive Performance Speedup v1.1Ruby Supercomputing - Using The GPU For Massive Performance Speedup v1.1
Ruby Supercomputing - Using The GPU For Massive Performance Speedup v1.1
Preston Lee
 
String handling
String handlingString handling
String handling
IyeTech - Pakistan
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
Daniel Nyagechi
 
Strings
StringsStrings
Strings
Saranya saran
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
kamal kotecha
 

Similar to What is the runtime complexity of Adams famous string splitter cod.pdf (18)

Python workshop intro_string (1)
Python workshop intro_string (1)Python workshop intro_string (1)
Python workshop intro_string (1)
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumar
 
Lec18
Lec18Lec18
Lec18
 
Rust - Fernando Borretti
Rust - Fernando BorrettiRust - Fernando Borretti
Rust - Fernando Borretti
 
Programming with Python
Programming with PythonProgramming with Python
Programming with Python
 
Rust vs C++
Rust vs C++Rust vs C++
Rust vs C++
 
Kotlin coroutines and spring framework
Kotlin coroutines and spring frameworkKotlin coroutines and spring framework
Kotlin coroutines and spring framework
 
C language sample test
C language sample testC language sample test
C language sample test
 
Common mistakes in C programming
Common mistakes in C programmingCommon mistakes in C programming
Common mistakes in C programming
 
Deduplication on large amounts of code
Deduplication on large amounts of codeDeduplication on large amounts of code
Deduplication on large amounts of code
 
Strings1
Strings1Strings1
Strings1
 
Huffman Code Decoding
Huffman Code DecodingHuffman Code Decoding
Huffman Code Decoding
 
Thnad's Revenge
Thnad's RevengeThnad's Revenge
Thnad's Revenge
 
Ruby Supercomputing - Using The GPU For Massive Performance Speedup v1.1
Ruby Supercomputing - Using The GPU For Massive Performance Speedup v1.1Ruby Supercomputing - Using The GPU For Massive Performance Speedup v1.1
Ruby Supercomputing - Using The GPU For Massive Performance Speedup v1.1
 
String handling
String handlingString handling
String handling
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
Strings
StringsStrings
Strings
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 

More from federaleyecare

A ISCSI SAN consists of Select one or more A. HBA B. LUN C. Fibr.pdf
A ISCSI SAN consists of  Select one or more  A. HBA  B. LUN  C. Fibr.pdfA ISCSI SAN consists of  Select one or more  A. HBA  B. LUN  C. Fibr.pdf
A ISCSI SAN consists of Select one or more A. HBA B. LUN C. Fibr.pdf
federaleyecare
 
Which of the following statements about tRNA molecules is TRUEMul.pdf
Which of the following statements about tRNA molecules is TRUEMul.pdfWhich of the following statements about tRNA molecules is TRUEMul.pdf
Which of the following statements about tRNA molecules is TRUEMul.pdf
federaleyecare
 
Write a C program to simulate the description below using semaphores.pdf
Write a C program to simulate the description below using semaphores.pdfWrite a C program to simulate the description below using semaphores.pdf
Write a C program to simulate the description below using semaphores.pdf
federaleyecare
 
When analyzing any particular primary source, historians must consid.pdf
When analyzing any particular primary source, historians must consid.pdfWhen analyzing any particular primary source, historians must consid.pdf
When analyzing any particular primary source, historians must consid.pdf
federaleyecare
 
What is Linux SecuritySolutionLinux Security is a module in.pdf
What is Linux SecuritySolutionLinux Security is a module in.pdfWhat is Linux SecuritySolutionLinux Security is a module in.pdf
What is Linux SecuritySolutionLinux Security is a module in.pdf
federaleyecare
 
What does personalized learning mean to you What does personal.pdf
What does personalized learning mean to you What does personal.pdfWhat does personalized learning mean to you What does personal.pdf
What does personalized learning mean to you What does personal.pdf
federaleyecare
 
What do patients in healthcare expect from their insurance company.pdf
What do patients in healthcare expect from their insurance company.pdfWhat do patients in healthcare expect from their insurance company.pdf
What do patients in healthcare expect from their insurance company.pdf
federaleyecare
 
Use Table A to find the number z such that the proportion of observa.pdf
Use Table A to find the number z such that the proportion of observa.pdfUse Table A to find the number z such that the proportion of observa.pdf
Use Table A to find the number z such that the proportion of observa.pdf
federaleyecare
 
Two of the main political systems are democracy and totalitarianism..pdf
Two of the main political systems are democracy and totalitarianism..pdfTwo of the main political systems are democracy and totalitarianism..pdf
Two of the main political systems are democracy and totalitarianism..pdf
federaleyecare
 
The procedure of transferring journal entries to the ledger accounts .pdf
The procedure of transferring journal entries to the ledger accounts .pdfThe procedure of transferring journal entries to the ledger accounts .pdf
The procedure of transferring journal entries to the ledger accounts .pdf
federaleyecare
 
The ProblemUsing C programming language write a program that simul.pdf
The ProblemUsing C programming language write a program that simul.pdfThe ProblemUsing C programming language write a program that simul.pdf
The ProblemUsing C programming language write a program that simul.pdf
federaleyecare
 
5. Joe and Sam are using Public Key encryption. Joe’s public and pri.pdf
5. Joe and Sam are using Public Key encryption. Joe’s public and pri.pdf5. Joe and Sam are using Public Key encryption. Joe’s public and pri.pdf
5. Joe and Sam are using Public Key encryption. Joe’s public and pri.pdf
federaleyecare
 
QUESTION 7 When using the indirect method to prepare the statement of.pdf
QUESTION 7 When using the indirect method to prepare the statement of.pdfQUESTION 7 When using the indirect method to prepare the statement of.pdf
QUESTION 7 When using the indirect method to prepare the statement of.pdf
federaleyecare
 
Q.1. Define noncontrolling (minority) interest. List three methods th.pdf
Q.1. Define noncontrolling (minority) interest. List three methods th.pdfQ.1. Define noncontrolling (minority) interest. List three methods th.pdf
Q.1. Define noncontrolling (minority) interest. List three methods th.pdf
federaleyecare
 
Picking a fruit-flavored or primary colored bean. overlapping event .pdf
Picking a fruit-flavored or primary colored bean.  overlapping event .pdfPicking a fruit-flavored or primary colored bean.  overlapping event .pdf
Picking a fruit-flavored or primary colored bean. overlapping event .pdf
federaleyecare
 
Part F - Viral Evolution and LysogenyOne hypothesis regarding the .pdf
Part F - Viral Evolution and LysogenyOne hypothesis regarding the .pdfPart F - Viral Evolution and LysogenyOne hypothesis regarding the .pdf
Part F - Viral Evolution and LysogenyOne hypothesis regarding the .pdf
federaleyecare
 
Match the following Data vs Information Reliability as it adds value .pdf
Match the following Data vs Information Reliability as it adds value .pdfMatch the following Data vs Information Reliability as it adds value .pdf
Match the following Data vs Information Reliability as it adds value .pdf
federaleyecare
 
Many organizations invest substantial resources in creating their ow.pdf
Many organizations invest substantial resources in creating their ow.pdfMany organizations invest substantial resources in creating their ow.pdf
Many organizations invest substantial resources in creating their ow.pdf
federaleyecare
 
Lets compare and contrast the national cultures of Egypt and Brazi.pdf
Lets compare and contrast the national cultures of Egypt and Brazi.pdfLets compare and contrast the national cultures of Egypt and Brazi.pdf
Lets compare and contrast the national cultures of Egypt and Brazi.pdf
federaleyecare
 
Great alveolar (type II) cells of the alveoli secrete a _______ t.pdf
Great alveolar (type II) cells of the alveoli secrete a _______ t.pdfGreat alveolar (type II) cells of the alveoli secrete a _______ t.pdf
Great alveolar (type II) cells of the alveoli secrete a _______ t.pdf
federaleyecare
 

More from federaleyecare (20)

A ISCSI SAN consists of Select one or more A. HBA B. LUN C. Fibr.pdf
A ISCSI SAN consists of  Select one or more  A. HBA  B. LUN  C. Fibr.pdfA ISCSI SAN consists of  Select one or more  A. HBA  B. LUN  C. Fibr.pdf
A ISCSI SAN consists of Select one or more A. HBA B. LUN C. Fibr.pdf
 
Which of the following statements about tRNA molecules is TRUEMul.pdf
Which of the following statements about tRNA molecules is TRUEMul.pdfWhich of the following statements about tRNA molecules is TRUEMul.pdf
Which of the following statements about tRNA molecules is TRUEMul.pdf
 
Write a C program to simulate the description below using semaphores.pdf
Write a C program to simulate the description below using semaphores.pdfWrite a C program to simulate the description below using semaphores.pdf
Write a C program to simulate the description below using semaphores.pdf
 
When analyzing any particular primary source, historians must consid.pdf
When analyzing any particular primary source, historians must consid.pdfWhen analyzing any particular primary source, historians must consid.pdf
When analyzing any particular primary source, historians must consid.pdf
 
What is Linux SecuritySolutionLinux Security is a module in.pdf
What is Linux SecuritySolutionLinux Security is a module in.pdfWhat is Linux SecuritySolutionLinux Security is a module in.pdf
What is Linux SecuritySolutionLinux Security is a module in.pdf
 
What does personalized learning mean to you What does personal.pdf
What does personalized learning mean to you What does personal.pdfWhat does personalized learning mean to you What does personal.pdf
What does personalized learning mean to you What does personal.pdf
 
What do patients in healthcare expect from their insurance company.pdf
What do patients in healthcare expect from their insurance company.pdfWhat do patients in healthcare expect from their insurance company.pdf
What do patients in healthcare expect from their insurance company.pdf
 
Use Table A to find the number z such that the proportion of observa.pdf
Use Table A to find the number z such that the proportion of observa.pdfUse Table A to find the number z such that the proportion of observa.pdf
Use Table A to find the number z such that the proportion of observa.pdf
 
Two of the main political systems are democracy and totalitarianism..pdf
Two of the main political systems are democracy and totalitarianism..pdfTwo of the main political systems are democracy and totalitarianism..pdf
Two of the main political systems are democracy and totalitarianism..pdf
 
The procedure of transferring journal entries to the ledger accounts .pdf
The procedure of transferring journal entries to the ledger accounts .pdfThe procedure of transferring journal entries to the ledger accounts .pdf
The procedure of transferring journal entries to the ledger accounts .pdf
 
The ProblemUsing C programming language write a program that simul.pdf
The ProblemUsing C programming language write a program that simul.pdfThe ProblemUsing C programming language write a program that simul.pdf
The ProblemUsing C programming language write a program that simul.pdf
 
5. Joe and Sam are using Public Key encryption. Joe’s public and pri.pdf
5. Joe and Sam are using Public Key encryption. Joe’s public and pri.pdf5. Joe and Sam are using Public Key encryption. Joe’s public and pri.pdf
5. Joe and Sam are using Public Key encryption. Joe’s public and pri.pdf
 
QUESTION 7 When using the indirect method to prepare the statement of.pdf
QUESTION 7 When using the indirect method to prepare the statement of.pdfQUESTION 7 When using the indirect method to prepare the statement of.pdf
QUESTION 7 When using the indirect method to prepare the statement of.pdf
 
Q.1. Define noncontrolling (minority) interest. List three methods th.pdf
Q.1. Define noncontrolling (minority) interest. List three methods th.pdfQ.1. Define noncontrolling (minority) interest. List three methods th.pdf
Q.1. Define noncontrolling (minority) interest. List three methods th.pdf
 
Picking a fruit-flavored or primary colored bean. overlapping event .pdf
Picking a fruit-flavored or primary colored bean.  overlapping event .pdfPicking a fruit-flavored or primary colored bean.  overlapping event .pdf
Picking a fruit-flavored or primary colored bean. overlapping event .pdf
 
Part F - Viral Evolution and LysogenyOne hypothesis regarding the .pdf
Part F - Viral Evolution and LysogenyOne hypothesis regarding the .pdfPart F - Viral Evolution and LysogenyOne hypothesis regarding the .pdf
Part F - Viral Evolution and LysogenyOne hypothesis regarding the .pdf
 
Match the following Data vs Information Reliability as it adds value .pdf
Match the following Data vs Information Reliability as it adds value .pdfMatch the following Data vs Information Reliability as it adds value .pdf
Match the following Data vs Information Reliability as it adds value .pdf
 
Many organizations invest substantial resources in creating their ow.pdf
Many organizations invest substantial resources in creating their ow.pdfMany organizations invest substantial resources in creating their ow.pdf
Many organizations invest substantial resources in creating their ow.pdf
 
Lets compare and contrast the national cultures of Egypt and Brazi.pdf
Lets compare and contrast the national cultures of Egypt and Brazi.pdfLets compare and contrast the national cultures of Egypt and Brazi.pdf
Lets compare and contrast the national cultures of Egypt and Brazi.pdf
 
Great alveolar (type II) cells of the alveoli secrete a _______ t.pdf
Great alveolar (type II) cells of the alveoli secrete a _______ t.pdfGreat alveolar (type II) cells of the alveoli secrete a _______ t.pdf
Great alveolar (type II) cells of the alveoli secrete a _______ t.pdf
 

Recently uploaded

The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
dot55audits
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
Chevonnese Chevers Whyte, MBA, B.Sc.
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 

Recently uploaded (20)

The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 

What is the runtime complexity of Adams famous string splitter cod.pdf

  • 1. What is the runtime complexity of Adam's famous string splitter code? Hint: Make sure to look into the source code for string.find() in the C++ std library. I’ve included that code (downloaded from GNU). static vector ring text string delimiter vector ring pieces int location text, (delimiter); inte start 0; //while we find something interesting while location string DRos)f build substring string piece text substr (start location start); (piece start location 1 //find again location ext find deli miter start); string piece text substr (start location start); pieseswRush bask (piece return pieces; Solution Assumption is we have text length as N and we have N-1 delimeters in that text. text.find() -->Takes O(n) time in the worst case to find the delimeter. vectorpieces; -->O(1) int location = text.find();delimeter-->At max O(n) while(location!=string.pos()){ . -> Runs N times string piece = text.substr(start,location-start); -->At max takes O(N) [Copying that many characters]*N times for while loop start = location+1; -->O(1) location = text.find(delimeter,start);-->At Max O(N) * N times for while loop So While loop will run N time as we have N-1 delmieters and each time finding substr() and find() on an average will take O(n). So overall time complexity is O(N2) } Thanks, let me know if there is any concern.