• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
July 12, 2024 |24.9K Views

Naive Algorithm for Pattern Searching

  Share   Like
Description
Discussion

Given a text txt[0..n-1] and a pattern pat[0..m-1], write a function search(char pat[], char txt[]) that prints all occurrences of pat[] in txt[]. You may assume that n > m. 
Examples:

Input:  txt[] = "THIS IS A TEST TEXT"
       pat[] = "TEST"

Output: Pattern found at index 10

Input:  txt[] =  "AABAACAADAABAABA"
       pat[] =  "AABA"

Output: Pattern found at index 0

       Pattern found at index 9
       Pattern found at index 12

Naive Algorithm for Pattern Searching:https://www.geeksforgeeks.org/naive-algorithm-for-pattern-searching/