473,624 Members | 2,471 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

the lowest number of comparisons in string matching

Hi,

I'm looking for the algorithm which does the lowest number of
comparison for the string matching problem (in the worst case).

I know that the complexity is liniar in the length of the strings, but
I'm interested in finding the actual number of comparisons.

The lowest number (theoretical) is m-n+1, but as far as I know no
algorithm has achived this limit.

(where m is the lenght of the text and n is the length of the pattern).

Thanks,
Laura

Sep 22 '06 #1
2 2715
laura wrote:
>
I'm looking for the algorithm which does the lowest number of
comparison for the string matching problem (in the worst case).

I know that the complexity is liniar in the length of the strings,
but I'm interested in finding the actual number of comparisons.

The lowest number (theoretical) is m-n+1, but as far as I know no
algorithm has achived this limit.

(where m is the lenght of the text and n is the length of the
pattern).
This is off-topic here. Try comp.programmin g. Cross posted and
followups set.

Search for Boyer-Moore and Knuth-Morris-Pratt algorithms.
Sedgewicks "Algorithms " covers it nicely. KMP is nice in that it
avoids backtracking and works with streams.

--
Some informative links:
news:news.annou nce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html

--
Posted via a free Usenet account from http://www.teranews.com

Sep 22 '06 #2
In article <11************ **********@e3g2 000cwe.googlegr oups.com>,
laura <la************ *@gmail.comwrot e:
>I'm looking for the algorithm which does the lowest number of
comparison for the string matching problem (in the worst case).
That's an algorithms question, not a C specific question, so you
are advised to check with a newsgroup that deals with algorithms.
>I know that the complexity is liniar in the length of the strings, but
I'm interested in finding the actual number of comparisons.
You haven't defined *which* "string matching problem" you are
dealing with. It is also rather odd that you are concentrating
on the worst case to the exclusion of the average case.

>The lowest number (theoretical) is m-n+1, but as far as I know no
algorithm has achived this limit.
That's not the theoretical limit when you take into account locale
problems and case sensitivity...
--
"law -- it's a commodity"
-- Andrew Ryan (The Globe and Mail, 2005/11/26)
Sep 22 '06 #3

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

Similar topics

5
4463
by: Randi | last post by:
I am having problems with this question: Write a C++ while statement that will input numbers from a file until the end of file is reached. Output the lowest number in the file. Ok, I do understand the logic, I believe the following for loop solves it from keyboard input. But how do you point to any given value from a file. You can't assign anything to a variable. Little lost on this one. Thanks, Kelsey
3
1389
by: Andy Fish | last post by:
In my XSLT stylesheet, if I call <xsl:number level="any" count="sdfsjdfjsdfksndfn"/> where there are no preceeding nodes called "sdfsjdfjsdfksndfn" I would expect it to return 0. However, on the XSLT processor I'm using (.net framework 1.1) it seems to return an empty string (or possibly an empty node set) I had a look here: http://www.w3.org/TR/xslt and I can't find any
10
9545
by: javuchi | last post by:
I'm searching for a library which makes aproximative string matching, for example, searching in a dictionary the word "motorcycle", but returns similar strings like "motorcicle". Is there such a library?
4
3957
by: Kelly B | last post by:
This is a simple string matching code from K&R2 (modified to match a user entered string from a text file) I tried to code an alternative strindex function(commented below) but it does not work ,i don't seem to understand where exactly am i going wrong Secondly using gets() can be a dangerous option if the user enters more characters than the array can hold.is there a safer way out of using gets()? #include<stdio.h> #include<stdlib.h>
8
2828
by: kumarboston | last post by:
Hi All, I have a string of around 500 characters(alphabets) and I have a 3 arrays storing the position "start, end and type" for that string. i am trying to do is to match these position to the string and highlight those positions on the web page. For example: string- ABCDREGYRIWJEKSALOPRHDAGRTPRTDBRTWASERFSDHSJHDS start_pos=5 end_pos=10 type=helix breaker start_pos=12
5
3062
by: Zamdrist | last post by:
Let's say I have a result set (records) containing numbers such as: 0 1 2 3 9 16 21 45
6
31514
Rabbit
by: Rabbit | last post by:
INTRODUCTION The Levenshtein Distance algorithm is an algorithm used to calculate the minimum number of edits required to transform one string into another string using addition, deletion, and substitution of characters. USES The most common use of the function is for approximate string matching. Since the function returns the minimum number of edits required to transform one string into another, the user can set the threshhold at which one...
4
13595
Rabbit
by: Rabbit | last post by:
INTRODUCTION An ngram is the subsequence of n units from a given sequence. These units can be words, characters, etc. For example, the 2-gram, or bigram, of the phrase "Hello World" is "He", "el", "ll", "lo", "o ", " W", "Wo", "or", "rl", and "ld". USES NGram modeling is often used to model natural languages. It is also used to predict the next item in a sequence. I.E., given an NGram model with frequencies of occurrence, you can predict...
0
8246
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8685
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8341
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8490
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7174
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4184
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2612
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
1
1796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.