Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DSA
  • Practice Pattern Searching
  • Tutorial on Pattern Searching
  • Naive Pattern Searching
  • Rabin Karp
  • KMP Algorithm
  • Z Algorithm
  • Trie for Pattern Seaching
  • Manacher Algorithm
  • Suffix Tree
  • Ukkonen's Suffix Tree Construction
  • Boyer Moore
  • Aho-Corasick Algorithm
  • Wildcard Pattern Matching
Open In App
Next Article:
Pattern Searching using C++ library
Next article icon

Pattern Searching

Last Updated : 05 Dec, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report
Try it on GfG Practice
redirect icon

Pattern searching algorithms are essential tools in computer science and data processing. These algorithms are designed to efficiently find a particular pattern within a larger set of data.

Pattern-Searching
Patten Searching

Important Pattern Searching Algorithms:

  • Naive String Matching : A Simple Algorithm that works in O(m x n) time where m is the length of the pattern and n is the length of the text.
  • Knuth-Morris-Pratt (KMP) Algorithm It preprocesses pattern and works in O(m + n) Time.
  • Rabin-Karp Algorithm : It uses hashing to compare the pattern with the text. It works in O(m x n) Time in worst case,
  • Aho-Corasick Algorithm : A deterministic finite automaton (DFA) based algorithm and works in O(m + n) time.

Learn Basics of Pattern Searching:

  • Introduction to Pattern Searching
  • Naive Pattern Searching

Standard Pattern Searching Algorithms:

  • Rabin-Karp Algorithm
  • KMP Algorithm
  • Z algorithm
  • Finite Automata
  • Boyer Moore – Bad Character Heuristic
  • Aho-Corasick Algorithm
  • Suffix Array
  • Kasai’s Algorithm for LCP array from Suffix Array
  • Online algorithm for checking palindrome in a stream
  • Manacher’s Algorithm
  • Ukkonen’s Suffix Tree Construction – Part 1
  • Generalized Suffix Tree

Practice Problems on Pattern Searching:

  • Frequency of a Substring
  • Anagram Substring Search
  • Check if Two Strings Rotations
  • Substrings with all Vowels
  • Substrings with only Given Character
  • Find all Occurrences of a Subarray
  • Pattern Searching using a Trie of all Suffixes
  • Wildcard Pattern Matching
  • Regular Expression Matching
  • Longest prefix which is also suffix
  • Count string in a 2D array
  • Find all the patterns of “1(0+)1”
  • Max length prefix as Subsequence
  • Search a Word in a 2D Grid
  • Word Search with Zig-Zag
  • Suffix Tree Application 1 – Substring Check

Applications of Pattern Searching

Pattern searching algorithms have numerous applications, including:

  • Text Processing: Searching for keywords in a document, finding and replacing text, spell checking, and plagiarism detection.
  • Information Retrieval: Finding relevant documents in a database, web search, and data mining.
  • Bioinformatics: Searching for DNA sequences in a genome, protein analysis, and gene expression analysis.
  • Network Security: Detecting malicious patterns in network traffic, intrusion detection, and malware analysis.
  • Data Mining: Identifying patterns in large datasets, customer segmentation, and fraud detection.

Recommended:

  • Learn Data Structure and Algorithms | DSA Tutorial
  • Practice problems on Pattern Searching

Next Article
Pattern Searching using C++ library

H

harendrakumar123
Improve
Article Tags :
  • Algorithms
  • Pattern Searching
  • DSA
Practice Tags :
  • Algorithms
  • Pattern Searching

Similar Reads

  • What is Pattern Searching ?
    Pattern searching in Data Structures and Algorithms (DSA) is a fundamental concept that involves searching for a specific pattern or sequence of elements within a given data structure. This technique is commonly used in string matching algorithms to find occurrences of a particular pattern within a
    5 min read
  • Pattern of Strings
    Given a string S of length N, find the pattern of the strings as shown below in the examples. Examples: Input: S = "Geek"Output: Geek, Gee, Ge, GExplanation: Decrease one character after each line Input: S = "G*g" Output: G*g, G*, GExplanation: Decrease one character after each line Using two Nested
    6 min read
  • Pattern Searching using C++ library
    Given a text txt[0..n-1] and a pattern pat[0..m-1], write a function that prints all occurrences of pat[] in txt[]. You may assume that n > m.Examples: Input : txt[] = "geeks for geeks" pat[] = "geeks" Output : Pattern found at index 0 Pattern found at index 10 Input : txt[] = "aaaa" pat[] = "aa"
    3 min read
  • Naive algorithm for Pattern Searching
    Given text string with length n and a pattern with length m, the task is to prints all occurrences of pattern in text. Note: You may assume that n > m. Examples:  Input:  text = "THIS IS A TEST TEXT", pattern = "TEST"Output: Pattern found at index 10 Input:  text =  "AABAACAADAABAABA", pattern =
    6 min read
  • Print Triangle separated pattern
    Given a number N, the task is to print the triangle-separated pattern. Triangle Separated Pattern: Pattern in which four triangles (left, down, right, up) are separated by forward and backward slash, see this below: \*****/ *\***/* **\*/** ***/*** **/*\** */***\* /*****\ Note: N should be an odd num
    6 min read
  • Y shaped pattern
    Print a ‘Y’ shaped pattern from asterisks in N number of lines. Examples: Input: N = 12Output: * * * * * * * * * * * * * * * * * * * Input: 8Output: * * * * * * * * * * * * * Approach: Follow the steps to solve this problem: Initialize two variable s = N / 2 and t = N / 2.Traverse a loop on i from 0
    4 min read
  • Wave Patterns
    Given length and width, print the pattern in wave form using '/' and ' '.Examples : Input : wave_height = 4 wave_length = 4 Output : /\ /\ /\ /\ / \ / \ / \ / \ / \ / \ / \ / \ / \/ \/ \/ \ Input : wave_height = 2 wave_length = 3 Output : /\ /\ /\ / \/ \/ \ C/C++ Code #include <iostream> using
    15+ min read
  • Program to print pattern
    Given the value of n, print the following pattern.Examples : Input : n = 4 Output : A1 AB12 ABC123 ABCD1234 Input : n = 7 Output : A1 AB12 ABC123 ABCD1234 ABCDE12345 ABCDEF123456 ABCDEFG1234567 Below is the implementation to print the above pattern : C/C++ Code // C++ program to print given pattern
    5 min read
  • Pattern Printing Problems
    In many interviews star, number, and character patterns are the Most Asked Pattern Programs to check your logical and coding skills. Pattern printing programs not only improve your understanding of loops but also sharpen your coding efficiency and creativity. To solve a pattern problem, first identi
    1 min read
  • Printing Heart Pattern in C
    How to print below heart pattern in C? AAAAAAA AAAAAA AAAAAAAAA AAAAAAAA AAAAAAAAAAA AAAAAAAAAA AAAAAAAAAAAAA AAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAA BBBBBBBBBBBBBBBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB
    8 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences