Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use BF algorithm to realize string matching in Java

Shulou Source: shulou.com Published: 2022-06-01 10:56:07 10月12日 Update

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

Tags: Characters strings algorithms patterns situations same content that is more knowledge length movement complexity practicality simplicity success success and then generally speaking from scratch Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Technology NVidia Huawei Xiaomi