🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: uw.cs.cs240
Article #1

Re: worst-case example for the Boyer-Moore algorithm

#1
From: ricky fan
Date: Thu, 15 Apr 2021 18:58
80 lines
4488 bytes
On Wednesday, March 25, 2009 at 10:55:31 AM UTC-4, Arash Farzan wrote:
> Robert Xiao wrote:
> > Arash Farzan wrote:
> >> Some students observed that the example given in class does not 
> >> produce the worst-case behavior of the Boyer-Moore algorithm. In fact 
> >> the example given beats the suffix shift heuristic but the character 
> >> jump heuristic compensates for it.
> >>
> >> It is indeed not easy to beat both heuristics at the same time: this 
> >> tells us about the power of the Boyer-Moore algorithm in practice.
> >>
> >>
> >> However, I have this construction which theoretically beats both 
> >> heuristics and achieves the worst-case O(nm) running time:
> >>
> >> T = (bb(ab)^(k-1))*
> >> P = (ab)^k
> >>
> >>
> >> for instance: T = bbababab bbababab bbababab bbababab ... (white 
> >> spaces are put for ease of read)
> >> P = abababab
> >>
> >>
> >> You can observe that the majority of shifts are shift by twos which 
> >> gives a O(nm) running time.
> > 
> > I'm sort of confused (as usual).
> > 
> > T=b*
> > P=a(b^k)
> > 
> > ...bbbbbbbbbbbbbbb...
> > .....abbbbbbbb...
> > .....X^^^^^^^^...
> > The mismatch causes the character shift to attempt to shift "to line up 
> > with the last occurrence of _b_ in P" where b is the character 
> > mismatched in T (which happens to be a "b"). But this would require 
> > shifting P *left* k positions. So, instead, it shifts by one position 
> > right -- this means that a pure character shift performs poorly.
> > 
> > Suffix shift, though, says that we should line up the characters already 
> > matched (b^k) with an occurrence of (b^k) further left; this is 
> > impossible, so the suffix shift will shift the whole way through.
> right.
> > 
> > ...or did I miss something?
> no.
> > 
> > 
> > There's another version of Boyer-Moore which is sometimes cited, and 
> > which (supposedly) has worst-case linear run-time. In this version, the 
> > suffix shift shifts to the left to align the already-matched suffix, but 
> > also specifies that the character immediately to the left of that suffix 
> > (i.e. the one which mismatched in T) must not be equal to the character 
> > in P in the current position -- this ensures that repeats, like that in 
> > the second example, are skipped over.
> > 
> > Using that example:
> > bbabababbbababab
> > ..abababab..
> > ........X^
> > 
> > Ordinary suffix shift would look for the next "b" in P, which is a shift 
> > of two. The improved suffix shift would look for the next "(not-a)b" in 
> > P, which doesn't occur at all, so it would shift right past.
> > 
> > This slight modification, as it turns out, was suggested by the diagram 
> > on slide 167 -- the "ordinary" suffix shift is described in words, but 
> > the "improved" suffix shift is what appears to be demonstrated (if you 
> > assume that a!=c).
> > 
> > Robert
> That slight modification (looking for a no non-fit character in front of 
> a good suffix) makes the algorithm to perform linearly. The version 
> presented in class (which is the original version) does not require a 
> different character in front and therefore performs in O(nm). And yes, 
> there is no implicit assumption on character 'c' being the same or 
> different from 'a' in that slide).
lkkl
Technical Details
Message-ID: <4c13c4cd-06fd-4a7d-ae73-0c8a53565acen@googlegroups.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!archive!apf2.newsdeef.eu!not-for-mail
References: <gqbku6$ik1$1@rumours.uwaterloo.ca> <gqcad2$r04$1@rumours.uwaterloo.ca> <gqdgla$5vj$1@rumours.uwaterloo.ca>

Show Full Headers
Complete Article Headers
Message-ID: <4c13c4cd-06fd-4a7d-ae73-0c8a53565acen@googlegroups.com>
Subject: Re: worst-case example for the Boyer-Moore algorithm
Date: Thu, 15 Apr 2021 18:58:46 +0000
From: ricky fan <rickyhzfan@gmail.com>
References: <gqbku6$ik1$1@rumours.uwaterloo.ca> <gqcad2$r04$1@rumours.uwaterloo.ca> <gqdgla$5vj$1@rumours.uwaterloo.ca>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!archive!apf2.newsdeef.eu!not-for-mail
X-Received: by 2002:ac8:6edb:: with SMTP id f27mr4241181qtv.303.1618513126717; Thu, 15 Apr 2021 11:58:46 -0700 (PDT)
X-Received: by 2002:ac8:4ccc:: with SMTP id l12mr4451878qtv.157.1618513126527; Thu, 15 Apr 2021 11:58:46 -0700 (PDT)
Newsgroups: uw.cs.cs240
In-Reply-To: <gqdgla$5vj$1@rumours.uwaterloo.ca>
Injection-Info: google-groups.googlegroups.com; posting-host=45.72.242.71; posting-account=J9Ih9woAAADFonJKxVyhyg33LTz9xn06
Nntp-Posting-Host: 45.72.242.71
User-Agent: G2/1.0
Mime-Version: 1.0
Injection-Date: Thu, 15 Apr 2021 18:58:46 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 79