From 36e30a011114e336d0e5bf6ea8d9e7129d5b3bda Mon Sep 17 00:00:00 2001 From: Prateek Kumar Oraon Date: Fri, 22 May 2020 03:53:05 +0530 Subject: [PATCH] String Matching using Finite Automata added in Others/StringMatchFiniteAutomata.java --- Others/StringMatchFiniteAutomata.java | 91 +++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 Others/StringMatchFiniteAutomata.java diff --git a/Others/StringMatchFiniteAutomata.java b/Others/StringMatchFiniteAutomata.java new file mode 100644 index 00000000..34eb60b7 --- /dev/null +++ b/Others/StringMatchFiniteAutomata.java @@ -0,0 +1,91 @@ +/** + * @author Prateek Kumar Oraon (https://github.com/prateekKrOraon) + */ +import java.util.Scanner; + +//An implementaion of string matching using finite automata +public class StringMatchFiniteAutomata{ + + public static final int CHARS = 256; + public static int[][] FA; + public static Scanner scanner = null; + + public static void main(String[] args){ + + scanner = new Scanner(System.in); + System.out.println("Enter String"); + String text = scanner.nextLine(); + System.out.println("Enter pattern"); + String pat = scanner.nextLine(); + + searchPat(text, pat); + + scanner.close(); + + } + + public static void searchPat(String text, String pat){ + + int m = pat.length(); + int n = text.length(); + + FA = new int[m+1][CHARS]; + + computeFA(pat, m ,FA); + + int state = 0; + for(int i=0;i0; ns--){ + + if(pat.charAt(ns-1) == x){ + + for(int i=0; i