In the brute force pattern matching algorithm when all the characters in the pattern are unique then brute force can be implemented in Big-oh(n) complexity where n is the length of the string (reference: introduction to algorithms). can anyone help me with the algorithm? Thanks in advance

Recommended Answers

All 3 Replies

Walk over the source once. Keep a reference to the first match and as long as the source matches the pattern, walk over the pattern too. If the pattern reaches the end of the string, you have a complete match. Otherwise, reset the pattern and start over.

If the pattern is allowed to use wild card characters, such as * and ? then it gets a bit trickier.

card characters gets a bit trickier.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.