473,550 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Which is the fastest pattern matching algorithm?

Hi!

I'm looking for a way to find the position of a certain pattern within a
string. On my search on the internet I've come accross various algorithms
such as Knuth-Morris-Pratt and Boyer-Moore (just to name two). But which is
the fastest?

Thanks already in advance!
Jul 21 '05 #1
2 2655
Run both in your real world conditions ;-)

Don't know but generally speaking you don't have a "faster" algorihtm. For
example one of these two could be quicker on small strings and the other
could be quicker on long strings, one could be quicker when there is
numerous close match etc etc.....

For a start I would use the regular expression that are readily available in
the .NET framework and that likely uses already something quite efficient.
Only if I can measure it doesn't fit my needs, I would then search if I
could do better. Try :

http://msdn.microsoft.com/library/de...ClassTopic.asp

(Also if the pattern is simple you could use the usual string functions...)

Patrice

--

"tommazzo" <to******@discu ssions.microsof t.com> a écrit dans le message de
news:80******** *************** ***********@mic rosoft.com...
Hi!

I'm looking for a way to find the position of a certain pattern within a
string. On my search on the internet I've come accross various algorithms
such as Knuth-Morris-Pratt and Boyer-Moore (just to name two). But which is the fastest?

Thanks already in advance!

Jul 21 '05 #2
Thanks a lot for your help! I'll conduct a few tests on both algorithms now.
However in the meantime I've already read that although the KMP algorithm has
a smaller number of worst-case character comparisons, the BM algorithm
usually turns up with the result after less comparisons and can thus be
considered more efficient.

"Patrice" wrote:
Run both in your real world conditions ;-)

Don't know but generally speaking you don't have a "faster" algorihtm. For
example one of these two could be quicker on small strings and the other
could be quicker on long strings, one could be quicker when there is
numerous close match etc etc.....

For a start I would use the regular expression that are readily available in
the .NET framework and that likely uses already something quite efficient.
Only if I can measure it doesn't fit my needs, I would then search if I
could do better. Try :

http://msdn.microsoft.com/library/de...ClassTopic.asp

(Also if the pattern is simple you could use the usual string functions...)

Patrice

--

"tommazzo" <to******@discu ssions.microsof t.com> a écrit dans le message de
news:80******** *************** ***********@mic rosoft.com...
Hi!

I'm looking for a way to find the position of a certain pattern within a
string. On my search on the internet I've come accross various algorithms
such as Knuth-Morris-Pratt and Boyer-Moore (just to name two). But which

is
the fastest?

Thanks already in advance!


Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
3193
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # Matching string patterns # # Sometimes you want to know if a string is of # particular pattern. Let's say in your website # you have converted all images files from gif # format to png format. Now you need to change the # html code to use the .png files. So, essentially
3
2737
by: Day Of The Eagle | last post by:
Jeff_Relf wrote: > ...yet you don't even know what RegEx is. > I'm looking at the source code for mono's Regex implementation right now. You can download that source here ( use the class libraries download ). http://www.mono-project.com/Downloads
0
1191
by: Yoon Soo | last post by:
Hi, there in the code below I am not sure, if the two 'big' for-loops are redundabt in some way. Could this be made also in one loop and would this make sense? Another question is,if I should implement the maps as bitmaps. (Pro & Contra..on a very first sight, it looked to me, as if the implemention as bitmap would be some more work).
2
6444
by: RobC | last post by:
I have noticed that in the directoryInfo class a method named GetFiles(String) accepts a wildcard pattern as a parameter and uses this to match file names that exist in a directory. I want to use the pattern matching agorithm it uses. Why is it not exposed to public access? Thank you.
60
49007
by: Julie | last post by:
What is the *fastest* way in .NET to search large on-disk text files (100+ MB) for a given string. The files are unindexed and unsorted, and for the purposes of my immediate requirements, can't be indexed/sorted. I don't want to load the entire file into physical memory, memory-mapped files are ok (and preferred). Speed/performance is a...
2
239
by: tommazzo | last post by:
Hi! I'm looking for a way to find the position of a certain pattern within a string. On my search on the internet I've come accross various algorithms such as Knuth-Morris-Pratt and Boyer-Moore (just to name two). But which is the fastest? Thanks already in advance!
5
5737
by: olaufr | last post by:
Hi, I'd need to perform simple pattern matching within a string using a list of possible patterns. For example, I want to know if the substring starting at position n matches any of the string I have a list, as below: sentence = "the color is $red" patterns = pos = sentence.find($)
8
3900
by: 116Rohan | last post by:
I came across a question in one of the Computing olympiad regarding string pattern matching. Write a program that will accept a fraction of the form N/D, where N is the numerator and D is the denominator, that prints out the decimal representation. If the decimal representation has a repeating sequence of digits, it should be indicated by...
9
4306
by: Chris | last post by:
Is anyone aware of any prior work done with searching or matching a pattern over nested Python lists? I have this problem where I have a list like: , 9, 9], 10] and I'd like to search for the pattern so that is returns: , 9, 9], 10] , 9, 9]
0
7490
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8001
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7520
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7846
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6104
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5404
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5129
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3533
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1980
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.