ArticleslgStudy

computer science

Raita algorithm

Raita algorithm is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Raita algorithm rather than just read about it. In short: In computer science, the Raita algorithm is a string searching algorithm which improves the performance of Boyer–Moore–Horspool algorithm. This algorithm preprocesses the string being searched for the pattern, which is similar to Boyer–Moore string-search algorithm.

Key takeaways

  • Raita algorithm belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Raita algorithm to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Raita algorithm from memory before moving on to harder problems.

Reference excerpt

In computer science, the Raita algorithm is a string searching algorithm which improves the performance of Boyer–Moore–Horspool algorithm. This algorithm preprocesses the string being searched for the pattern, which is similar to Boyer–Moore string-search algorithm. The searching pattern of particular sub-string in a given string is different from Boyer–Moore–Horspool algorithm. This algorithm was published by Timo Raita in 1991.

Description Raita algorithm searches for a pattern "P" in a given text "T" by comparing each character of pattern in the given text. Searching will be done as follows. Window for a text "T" is defined as the length of "P".

First, last character of the pattern is compared with the rightmost character of the window. If there is a match, first character of the pattern is compared with the leftmost character of the window. If they match again, it compares the middle character of the pattern with middle character of the window. If everything in the pre-check is successful, then the original comparison starts from the second character to last but one. If there is a mismatch at any stage in the algorithm, it performs the bad character shift function which was computed in pre-processing phase. Bad character shift function is identical to the one proposed in Boyer–Moore–Horspool algorithm. A modern formulation of a similar pre-check is found in std::string::find, a linear/quadratic string-matcher, in libc++ and libstdc++. Assuming a well-optimized version of memcmp, not skipping characters in the "original comparison" tends to be more efficient as the pattern is likely to be aligned.

C Code for Raita algorithm

Example Pattern: abddb Text:abbaabaabddbabadbb Pre- Processing stage:

a b d 4 3 1

Attempt 1: abbaabaabddbabadbb ....b Shift by 4 (bmBc[a])

Comparison of last character of pattern to rightmost character in the window. It's a mismatch and shifted by 4 according to the value in pre-processing stage.

Attempt 2: abbaabaabddbabadbb A.d.B Shift by 3 (bmBc[b])

Here last and first character of the pattern are matched but middle character is a mismatch. So the pattern is shifted according to the pre-processing stage.

Attempt 3: abbaabaabddbabadbb ABDDB Shift by 3 (bmBc[b])

We found exact match here but the algorithm continues until it can't move further.

Attempt 4: abbaabaABDDBabadbb ....b Shift by 4 (bmBc[a])

At this stage, we need to shift by 4 and we can't move the pattern by 4. So, the algorithm terminates. Letters in capital letter are exact match of the pattern in the text.

Complexity Pre-processing stage takes O(m) time where "m" is the length of pattern "P". Searching stage takes O(mn) time complexity where "n" is the length of text "T".

See also Boyer–Moore string-search algorithm Boyer–Moore–Horspool algorithm

References

External links Applet animation and Description for Raita Algorithm

Worked examples

Example 1 — a first encounter with Raita algorithm

Start with the simplest possible case. Write down what Raita algorithm claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Raita algorithm before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Raita algorithm ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Raita algorithm

In research
Raita algorithm appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Raita algorithm in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Raita algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics String matching algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Raita algorithm outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Raita algorithm” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Raita algorithm in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Raita algorithm means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Raita algorithm out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Raita algorithm in simple terms?

In computer science, the Raita algorithm is a string searching algorithm which improves the performance of Boyer–Moore–Horspool algorithm. This algorithm preprocesses the string being searched for the pattern, which is similar to Boyer–Moore string-search algorithm.

Why does Raita algorithm matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Raita algorithm?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Raita algorithm.

Tags

  • String matching algorithms

Keep exploring