Hi,
Please give any hint on the question
Wildcard pattern matching doubt
While solving a string you will encounter multiple cases, letβs discuss them.
- Case 1: The character is β*β Now you will see that Here two cases Will arise
Either We can ignore β * β character and move to next character in the Pattern.
Or β* β character matches with one or more characters in Text. In this case we will move to next character of the string.
-
Case 2: if The character is β?β We can ignore current character in Text and move to next character in the Pattern and Text.
-
Case 3: if The character is not a wildcard character If current character in Text matches with current character in Pattern, we move to next character in the Pattern and Text. If they do not match, wildcard pattern and Text do not match.
So , dp relation come is
//If current character of each string matches then mark this as however its previous state was
dp[i][j] = dp[i-1][j-1];
//As β?βcan be mapped with all characters , do the same for this as well
dp[i][j] = dp[i-1][j-1];
//As * can be mapped with all strings , mark current state as OR of both previous states
dp[i][j] = dp[i-1][j] || dp[i][j-1] ;
//Since no matching took place , mark this cell as false
dp[i][j] = false ;
I hope Iβve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.