473,378 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 2630
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******@discussions.microsoft.com> a écrit dans le message de
news:80**********************************@microsof t.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******@discussions.microsoft.com> a écrit dans le message de
news:80**********************************@microsof t.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
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...
3
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...
0
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...
2
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...
60
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...
2
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...
5
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...
8
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...
9
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.