Link Search Close Search Menu Expand Document

Brute-Force String Search Algorithm

Brute-Force or Naive String Search algorithm searches for a string (also called pattern) within larger string.
It checks for character matches of pattern at each index of string.
If all characters of pattern match with string then search stops.
If not, it shifts to the next index of string for check.
It has worst case complexity of O(mn). Where m is length of pattern and n is length of string.

Visualization of Brute-Force String Search Algorithm

Implementation of Brute-Force String Search Algorithm





Back to top

Copyright © 2020-2021 Gajanan Bhat. All rights reserved.