SlideShare a Scribd company logo
1 of 1
Download to read offline
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 SujithKumarSujith Kumar
 
Rust - Fernando Borretti
Rust - Fernando BorrettiRust - Fernando Borretti
Rust - Fernando BorrettiTryolabs
 
Kotlin coroutines and spring framework
Kotlin coroutines and spring frameworkKotlin coroutines and spring framework
Kotlin coroutines and spring frameworkSunghyouk Bae
 
C language sample test
C language sample testC language sample test
C language sample testSompal Duhan
 
Common mistakes in C programming
Common mistakes in C programmingCommon mistakes in C programming
Common mistakes in C programmingLarion
 
Deduplication on large amounts of code
Deduplication on large amounts of codeDeduplication on large amounts of code
Deduplication on large amounts of codesource{d}
 
Huffman Code Decoding
Huffman Code DecodingHuffman Code Decoding
Huffman Code DecodingRex Yuan
 
Thnad's Revenge
Thnad's RevengeThnad's Revenge
Thnad's RevengeErin 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.1Preston Lee
 
String and string buffer
String and string bufferString and string buffer
String and string bufferkamal 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.pdffederaleyecare
 
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.pdffederaleyecare
 
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.pdffederaleyecare
 
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.pdffederaleyecare
 
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.pdffederaleyecare
 
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.pdffederaleyecare
 
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.pdffederaleyecare
 
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.pdffederaleyecare
 
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..pdffederaleyecare
 
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 .pdffederaleyecare
 
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.pdffederaleyecare
 
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.pdffederaleyecare
 
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.pdffederaleyecare
 
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.pdffederaleyecare
 
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 .pdffederaleyecare
 
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 .pdffederaleyecare
 
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 .pdffederaleyecare
 
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.pdffederaleyecare
 
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.pdffederaleyecare
 
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.pdffederaleyecare
 

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

Climbers and Creepers used in landscaping
Climbers and Creepers used in landscapingClimbers and Creepers used in landscaping
Climbers and Creepers used in landscapingDr. M. Kumaresan Hort.
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxLimon Prince
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptxPoojaSen20
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptxVishal Singh
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 

Recently uploaded (20)

Climbers and Creepers used in landscaping
Climbers and Creepers used in landscapingClimbers and Creepers used in landscaping
Climbers and Creepers used in landscaping
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 

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.