Forem

Daniel
Daniel

Posted on

Algorithms Day 2- Naive String Search

This algorithm works if you wanna search a smaller string inside a longer string. And they'll return the no of occurrences of that small string.

Naive Search - Pseudocode

  • Create a function that accepts a long string and a shorter string

  • Loop over the longer string. Inside that, we should loop over the smaller string.

  • If the string characters don't match we should break out from the inner loop

  • If the string matches we need to continue the loop for the rest of the smaller string

  • If the match was found we should increment the no of matches

  • Finally, we need to return the count.

  • The code is mentioned below

Thanks for reading. Hope you'll find it useful

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay