I am trying to figure out the time complexity for "Regular Expression Matching" problem. Problem statement is simple, only meta characters allowed are '.' and '*'. Actual problem statement can be found in Link
The solution is in java and I have solved it using memoization, but having difficulty to compute the time complexity. Can anyone help me with the explanation, and any reference documents or link to study further on this subject.
1 public boolean isMatch(String s, String p) {
2 return backTrack(s, 0, p, 0, new Boolean[s.length() + 1][p.length() + 1]);
3 }
4 boolean backTrack (String s, int si, String p, int pi, Boolean[][] dp) {
5 if (pi >= p.length()) return si >= s.length();
6 if (dp[si][pi] != null) return dp[si][pi];
7 if (pi < p.length() - 1 && p.charAt(pi + 1) == '*') {
8 if (si < s.length() && (s.charAt(si) == p.charAt(pi) || p.charAt(pi) == '.')) {
9 if (backTrack(s, si + 1, p, pi + 2, dp)) return dp[si][pi] = true;
10 if (backTrack(s, si + 1, p, pi, dp)) return dp[si][pi] = true;
11 }
12 if (backTrack(s, si, p, pi + 2, dp)) return dp[si][pi] = true;
13 }
14 if (si < s.length() && (s.charAt(si) == p.charAt(pi) || p.charAt(pi) == '.')) {
15 if (backTrack(s, si + 1, p, pi + 1, dp)) return dp[si][pi] = true;
16 }
17 return dp[si][pi] = false;
18 }