Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use BF algorithm to realize string matching in Java

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to use BF algorithm to achieve string matching in Java". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Concept

Single-pattern string matching is the matching of one string a with another string B. generally speaking, the length of an is much longer than b, and we look in a to see if b is included. We call the string a the main string and the string b the pattern string.

BF algorithm

BF algorithm has become a violent matching algorithm, also known as naive matching algorithm. It's also the simplest algorithm that we often use. The simplest method is to compare m characters at a time, and compare n-m+1 times in the worst case. The worst-case time complexity of BF algorithm is O (nymph).

Steps

1 the mode string is compared with the main string character one by one. If it is the same, then the main string is different, then the main string moves one bit, and then the pattern string is compared from scratch.

Package com.github.strings;public class bf {public static int search (String str,String pat) {int sLen = str.length (); / / main string int pLen = pat.length (); / / pattern string length / / number of times to match for (int itemositi

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report