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