0
$\begingroup$

I have some doubts about the need for backward checking in the Horspool algorithm.

  • The shift value depends only on the last character of the current window in the text. Whether the substring comparison is done forward or backward doesn’t affect the shift itself. Backward checking might avoid an extra access to retrieve the last character, but that seems negligible.

  • The goal of the comparison phase is to detect mismatches as early as possible to avoid unnecessary work. However, when the window is shifted, it is shifted so that the last occurrence of the mismatching character (from the pattern, excluding its last character) aligns with that character in the text. In this context, backward checking may end up checking these two aligned characters earlier than forward checking would—possibly leading to a comparison that don’t help avoid work any better than a forward check would.

Why is backward checking truly better than forward checking in the Horspool algorithm?

asked Mar 3 at 13:01
$\endgroup$

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.