In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to realize naive pattern matching algorithm in C language". In daily operation, I believe that many people have doubts about how to realize naive pattern matching algorithm in C language. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for everyone to answer the doubt of "how to realize naive pattern matching algorithm in C language". Next, please follow the editor to study!
What is the pattern matching of strings?
String pattern matching: find the same substring as the pattern string in the main string and return its location.
Note:
①, substring-- part of the main string, must exist.
②, pattern string-- may not be found in the main string
2. Naive pattern matching algorithm
The length of main string is n and the length of mode string is m.
Naive pattern matching algorithm: compare all the m-length substrings in the main string with the pattern string matching in turn until a perfectly matched substring is found, or all the substrings do not match.
Compare n-m+1 substrings at most
(1) implement naive pattern matching algorithm through array subscript
If the current string matching fails, the main string pointer I points to the first position of the next string, and the pattern string pointer j returns to the first position of the pattern string.
If j > T.length, the current string matches successfully and returns the position of the first character of the current string-I-T.length
Int Index (SString S, SString T) {int iTunes 1 while (I > m)
two。 Best time complexity O (n)
In the best case, the first character of each string fails to match, with a total of n-m+1 strings with a complexity of O (n-m+1) = O (n).
Note: in many cases, n > m
At this point, the study of "how to achieve naive pattern matching algorithm in C language" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.