Wildcard Matching Dynamic Programming

Поделиться
HTML-код
  • Опубликовано: 4 ноя 2024

Комментарии • 189

  • @MasterSergius
    @MasterSergius 4 года назад +39

    Thanks to all Indian guys on RUclips, I'm a well-paid software engineer!

    • @rajeevsingh5453
      @rajeevsingh5453 4 года назад

      yo wtf have u posted in yur channel man like wtf?????

  • @abhishekrbb9111
    @abhishekrbb9111 8 лет назад +6

    I must tell u I failed drastically to understand any DP solution by reading books or online written explanation .. your video has helped me improve drastically . now with ur help i am able to visualise dp based problems

  • @rupesh_dharme
    @rupesh_dharme 2 года назад +4

    To get all test cases you need a different initialization for the pattern index. You can initialize it with the previous value on the pattern index if the current letter is a '*' or else false.

    • @dominic_lee
      @dominic_lee 2 года назад

      thank you so much for this comment

  • @securelyinsaycure
    @securelyinsaycure Год назад

    The only video I have watched so many times at different stages of my career(*pure gold*).

  • @dera_ng
    @dera_ng 2 года назад

    Wow... There is a sort of beauty in dynamic programming.

  • @kitty_tax
    @kitty_tax 8 лет назад +16

    Hey Tushar,
    At 10:25 you are comparing "x?y" and "xa which is essentially T[i-1][j-1] but the code on the white-board states that T[i][j] = T[i][j-1] || T[i-1][j].
    If pattern[j]=='?' then T[i][j] = T[i][j-1] || T[i-1][j] || T[i-1][j-1];

    • @rahulagrawal3611
      @rahulagrawal3611 3 года назад +1

      yup correct. Also not clear in 12:05 "2nd case(considering * as non null character)" why the last character of string is removed but * from pattern is not removed. Anybody?

    • @codewithsunny981
      @codewithsunny981 3 года назад +4

      He mistakenly removed the '*' character but explained correctly....comparison should be in x?y* and xa.

  • @neelesh2023
    @neelesh2023 3 года назад

    your energy level is on another level

  • @summermoonspace
    @summermoonspace 7 лет назад +1

    I finally get to understand wildcard matching (and hopefully regular expression soon)!!! This is the lc question that I've been confused for so long time! I'm crying!!! Thank you so much:)

  • @we_crood
    @we_crood Год назад

    7 years OLD still GOLD

  • @techbarikcom
    @techbarikcom 4 года назад

    Wow! Explanation was super simple and clear. Thank you so much tushar****

  • @jellydg988
    @jellydg988 8 лет назад +2

    Thanks for the videos, please keep making them. Will recommend to all my friends~

  • @ymnik100
    @ymnik100 8 лет назад +1

    In the second case, when * is treated as a non-zero sequence we take a value from the top ( T[i-1][j] ) that means * has consumed the i-th character in the string, j still with no change and, as long as I understand, we shouldn't erase * character from the pattern ( ruclips.net/video/3ZDZ-N0EPV0/видео.html )
    By the way, want to say thanks to you, Tushar Roy for this video and what you are doing, it is really helpful. Hope to see more videos and tutorials from you.

  • @crystal101-77
    @crystal101-77 Год назад

    Brilliant explaination sir❤

  • @ivandrofly
    @ivandrofly 7 месяцев назад

    This video is crucial for dynamic programing tabulation approach - Thank you Tushar

  • @AbhishekKumar-oj4zm
    @AbhishekKumar-oj4zm 8 лет назад

    tushar sir u r making our path easier

  • @srikantadatta8695
    @srikantadatta8695 8 лет назад +2

    As usual excellent work Tushar! You rock man! Keep continuing the good work buddy!

  • @queueoverflow
    @queueoverflow 2 года назад

    Thanks a lot. I understand when i see the picture.

  • @ialpha6431
    @ialpha6431 6 лет назад +2

    For case 2:
    Matching the pattern this way might help in understanding --
    b a *
    b a
    or
    b a *
    b a

  • @sauravagrawal5013
    @sauravagrawal5013 5 лет назад +2

    Can be further optimised by using boolean T[][]=new boolean[string.length+1][writeIndex+1]; and changing (int j=1;j

  • @piyushsharma1638
    @piyushsharma1638 4 года назад

    Very easy way of explanation , thanks.

  • @arna591
    @arna591 7 лет назад

    BEST WILDCARD MATCHING EXPLANATION EVER.

  • @atouba-0
    @atouba-0 2 года назад

    Excellent explanation

  • @TL-fe9si
    @TL-fe9si 7 лет назад

    Your videos help me a lot! I just want to say thank you!

  • @anshusharma11
    @anshusharma11 8 лет назад +2

    All your videos are awesome.. You are the best teacher.

  • @anilduttyemmanuru6359
    @anilduttyemmanuru6359 3 года назад

    Great explanation. Thank you.

  • @vipulmishra8682
    @vipulmishra8682 3 года назад

    Clear and concise explanation!

  • @tomma1268
    @tomma1268 6 лет назад

    Awesome, That's great video. I prefer to keep T[i][j] = T[i][j-1] || T[i-1][j] || T[i-1][j-1] if (pattern[j] == *) without optimization for easy understanding.

  • @sharma-raju
    @sharma-raju 4 года назад

    Thank you so much for a such great explanation

  • @dileepmeena8749
    @dileepmeena8749 7 лет назад +11

    can we match empty string ( ' ' ) with * ( because * also match 0th string)..??

  • @polavenki
    @polavenki 7 лет назад +43

    10:44 - we shouldn't wipe "*" in the explanation part?

    • @vasanthykolluri
      @vasanthykolluri 7 лет назад +2

      totally agree...this is most trickiest part of the algo.
      @Tushar: Pls add that explanation if possible.Thanks in advance.

    • @dy0953
      @dy0953 6 лет назад +4

      @Vasanthy, T[i][j-1] represents if * is an empty char then you just need to look at previous match result on the left, T[i-1][j] represents if * matches one or multiple chars, then you look at the top, since top already match the current char.

    • @sudheerkumar4130
      @sudheerkumar4130 6 лет назад

      Correct , thank god you raised this concern

    • @nathann4291
      @nathann4291 5 лет назад +1

      @@dy0953 what does "since top already match the current char" mean?

    • @ankuragarwal4014
      @ankuragarwal4014 5 лет назад

      @@dy0953 what does "since top already match the current char" mean? please tell about it

  • @anonymoussloth6687
    @anonymoussloth6687 3 года назад

    at 15:20 you also have to see the case if the pattern in any number of stars in the begininng. For ex: if pattern is "***a" then the T[0][1], T[0][2], T[0][3] all will be true

  • @aviadshiber6232
    @aviadshiber6232 2 года назад +1

    thanks for the video. well explained.
    when I first approached the problem I thought how can I solve this without any non-constant space.
    regular expressions need only constant number of states (finite automata) , hence the use of non constant space is redundant (using extra matrix for dp).
    can you perhaps show how can this be done this way?

  • @miracledoh4020
    @miracledoh4020 5 лет назад +1

    why do you need to replace multiple ** into one *? we can just look at the previous T[i][j-1] to check for the first row, i.e.
    //in the case of "a**b" the T will be all false
    for (int j = 1; j < T[0].length; j++) {
    if (pattern[j - 1] == '*') {
    T[0][j] = T[0][j - 1];
    }
    }

  • @kamalsmusic
    @kamalsmusic 8 лет назад +8

    The case for the star where you examine T[i-1][j], is that assuming the star matches the character at i and you are seeing if it matches more?

    • @guangyang5116
      @guangyang5116 5 лет назад +4

      Yes, it should be explained in this way. Otherwise, it should be T[i-1][j-1] if we follow the explanation from author, which however is wrong.

  • @metaalphabrawlstars7697
    @metaalphabrawlstars7697 8 лет назад

    GOOD EXPLANATION AND THE BEST VIDEO ON RUclips ABOUT THE REGULAR EXPRESSION MATCHING. tHANKS VERY MUCH

  • @soumavomondal2705
    @soumavomondal2705 7 лет назад +4

    this is some great explanation. could you please introduce the case where there is a special character (say '+') where it matches at least one character of the previous sequence? thanks in advance :)

    • @vitaliistoian
      @vitaliistoian 5 лет назад +1

      It's explained here: ruclips.net/video/l3hda49XcDE/видео.html

  • @cantwaittowatch
    @cantwaittowatch 8 лет назад +1

    Great explanation Tushar. A clarification here, which I surmise you did, but while tracing of the 3rd row, that is 'y' and 4th column where there is a '*', you mentioned at the tail end to take the true value from T[3][3].
    Is it that, if any value is true in either T[3,3] or T[2,4] - then fill the resultant T[3][3] with T?
    Thanks

  • @siddharthagarwal8662
    @siddharthagarwal8662 8 лет назад

    Good Explanation Tushar!!

  • @nikhilbhardwaj6055
    @nikhilbhardwaj6055 6 лет назад +2

    sir if there is * in pattern then we should check left, upside and 'DIAGONALLY' also otherwise some test cases will be failed

    • @vivek5562
      @vivek5562 5 лет назад

      I was also thinking about same.
      if you match * with "a" then this will fail.

    • @sameerranjan2039
      @sameerranjan2039 4 года назад

      @@vivek5562 * and "a" should match and if u follow this algorithm it does match. It doesn't fail.

  • @ryanben3988
    @ryanben3988 Год назад

    I solved it using recursion and memoization. It is because of this video I have realized my Dynamic Programming is trash. Nice video (I think), I did not actually understand it🥲...I will comeback after solving some medium problems with dynamic programming, hopefully I will get the logic behind.

  • @amanpreetsinghbawa1600
    @amanpreetsinghbawa1600 8 лет назад

    Tushar excellent recursive relation
    please include recursive relation in every DP soln. as it gives insight to the problem very quickly.
    Thanks!!

  • @nehaagrawal5457
    @nehaagrawal5457 8 лет назад +1

    Another awesome explanation!I have a question. I didn't get the part when character is * and you take the value from either top or left. If top and left value don't match , we will get true in some cases and false in others since it's an OR. In your example , if you would have taken false instead of true , final answer would have been different. How does it work?

  • @kshitijjain8544
    @kshitijjain8544 8 лет назад +1

    What an awesome explanation!

  • @curiosull
    @curiosull 6 лет назад

    I know that it is simpler to implement (this method), but it is way harder to understand than a Finite State Machine solution.

  • @jinliu5928
    @jinliu5928 8 лет назад

    Great explanation! Thanks for the help!

  • @ewibowo74
    @ewibowo74 4 года назад

    I don't understand about his explanation at 5:02 that * match empty string. However, he wrote F for matrix 0 and *.

    • @kishores5121
      @kishores5121 3 года назад

      If the star would have appeared at the beginning of the pattern then he would've marked it as true, but for this case, where string = "" and pattern = "abc*" it shouldn't show true!

  • @kanikaverma6409
    @kanikaverma6409 3 года назад

    Why and how we conclude we need to perform DP at 2:02 sec of video ? How we understand when we need to apply DP ? because DP always optimizations . What's Brute force way ? Guess we need to show that in interview before we jump to DP. Rigth ?

  • @xw7628
    @xw7628 4 года назад

    Roy teaching pattern matching while wearing v clashing patterns

    • @shariqueshahab
      @shariqueshahab 4 года назад

      You mean teaching patterns matching while wearing anti pattern dress ?

  • @kkk7410
    @kkk7410 8 лет назад

    Normally while checking if a pattern matches a given input ,we start from left of both input and pattern and move to right till the end by comparing both the input and the pattern.
    In DP should we think in a different way as if we are comparing from right to left and is this is the reason when you have P[j]=* then we have T[i-1][j] as we are expecting more characters for * in input while moving in left direction.
    This is to understand DP intuitively as the * matching case is little confusing how it works conceptually.

    • @kkk7410
      @kkk7410 8 лет назад

      +kk k Also ,if this has to work for right to left,the pattern should be symmetrical ?

    • @kkk7410
      @kkk7410 8 лет назад

      +Tushar Roy I believe the example that you showed is from right to left itself and hence when p[j]=='*' and for case where there are more * characters you use T[i-1][j] ? Am I right ?

    • @kkk7410
      @kkk7410 8 лет назад

      +Tushar Roy Sorry to bother u so much.Thanks for your time.
      For a string s[0-i] ,I assume 0 to be at left and going from 0 to i meaning moving right and hence i to be at the right.
      To decide if T[i][j] is a match which means s[0-i] matches p[0-j] you are first comparing the last characters(right most for the given string which ends at i and pattern which ends at j and the based on ith and jth comparision decrementing either i or j or both by one such as T[i-1][j-1] )
      1)if s[i]==p[j] then T[i][j]=p[i-1][j-1]
      2)if p[j]=='*' then T[i][j] = dp[i-1][j] for more * sequence || dp[i][j-1] for zero * sequence.
      If you were comparing the string and pattern from left to right then for a given string s[0-i] and pattern[0-j] you should start comparing from left i.e zeroth positions of both string and pattern and then move towards end i.e right side.Isnt it ?Also if it is left to right ,for a given T[i][j] for the case when p[j]=='*' and when * is a sequence of characters ,you are taking T[i-1][j] ,shouldn't it be T[i+1][j] ?
      I understand that this DP is a bottom up approach but for a specific T[i][j] you are starting the comparision from extreme right of both string and pattern and moving towards left.
      I was tring to solve articles.leetcode.com/regular-expression-matching/ through DP and couldnt understand how to use DP to match * which means 0 or more of previous character and came across your explanation.

  • @user-re6yu6xk6d
    @user-re6yu6xk6d 5 лет назад

    Wow, excellent explanation!

  • @sahilsoni6090
    @sahilsoni6090 8 лет назад +6

    Is it necessary to convert multiple stars into one or can we keep them as it is ?

    • @jdragon8184
      @jdragon8184 4 года назад

      u can keep stars that are seperated by ? or even characters , also if missing subsequence is not possible we can use the multiple stars to combine various subsequence to form missing subsequences

  • @dush
    @dush 5 лет назад

    You are god send Tushar

  • @timbabb2508
    @timbabb2508 Год назад

    I'm here because CoPilot suggested this video in an auto-completed comment. (yes really)

  • @mohitgautam6365
    @mohitgautam6365 4 года назад

    Thank you it would help a lot to me

  • @shobhitchaturvediindia
    @shobhitchaturvediindia 8 лет назад

    like your videos simple and effective..

  • @vanihemmige
    @vanihemmige 5 лет назад

    Thanks for the great video and the detailed explanation. I have a doubt at point 5:06 of the video. You said pattern * can match with empty string. Then why is T[0][4] False? Should it not be True?

    • @DheerajKumarBarnwal
      @DheerajKumarBarnwal 5 лет назад

      First try to understand what T[i][j] represent, then you will get your answer

    • @pranayreddy6337
      @pranayreddy6337 3 года назад

      The * pattern can be used to match with 0 or more characters..so in your case for NULL string, if pattern itself starts with * then it it okay..BUT as there is already a pattern BEFORE *, NULL can't match with * as it would theoretically mean that the pattern before * has matched to NULL. Got it?

  • @benjaminrogge4959
    @benjaminrogge4959 8 лет назад

    Thanks for the great video! Is it correct that this algorithm won't work, if you have wildcards in the front of your pattern?

    • @benjaminrogge4959
      @benjaminrogge4959 8 лет назад

      +Tushar Roy you are right. My initial implementation was wrong

  • @VanjeAv
    @VanjeAv Год назад

    Amazing thank you

  • @Official-tk3nc
    @Official-tk3nc 4 года назад +1

    He looks like Gautam Gambir. Agree?

  • @ssjohnsmith3
    @ssjohnsmith3 3 года назад

    If the "*" is at the start of the pattern taking it from left or above should fail.

  • @daniyaryeralin9813
    @daniyaryeralin9813 6 лет назад +2

    I love you man! :D I wish I could get you a beer

  • @ivandrofly
    @ivandrofly 7 месяцев назад

    11:27 - Very important part on the video

  • @venkatesanr89
    @venkatesanr89 5 лет назад

    Why do we need to compute all the values in T[][] ? Incrementing the positions in String and expression till the end using recursion gives the best time complexity ?

  • @apexstate3127
    @apexstate3127 4 года назад

    x.y*z is not Equal to xaylmz. Because of in Expression y is occure n times including NUll but in String after y->lm is Encounter . So my Question is How * match lm ?

  • @mariochavez3546
    @mariochavez3546 3 года назад

    gracias por este video amigo :)

  • @harishgovindan
    @harishgovindan 4 года назад +1

    Thanks for the video. The solution seems to work fine.
    However, I would really appreciate if you could comment/explain on how you arrived at this solution.
    (The usual way to solve this would be to do a character-compare across two strings and use an additional loop for '*' character. That may / may not be the best solution. This would actually avoid a 2-D array and O(mn) complexity... instead it would be O(m) or O(n) right?. But not sure how/why I would arrive at the solution in the video)

  • @muzgash97
    @muzgash97 7 лет назад

    Great work thank you!

  • @rahulagrawal3611
    @rahulagrawal3611 3 года назад

    Not clear in 12:05 "2nd case(considering * as non null character)" why the last character of string is removed but * from pattern is not removed. Anybody?

  • @himanshijain7585
    @himanshijain7585 8 лет назад +1

    All your videos are really helpful.But i did not get the comparison of '*". How '*' replaces that character and if it does then we will compare pattern: x ? y y with text: x a

    • @amanpreetsinghbawa1600
      @amanpreetsinghbawa1600 8 лет назад

      either * can be used as 0 sequence
      if that is the case then we get the value from the above cell
      else if * is used as a sequence > 0 then it means * has been consumed by the current matching so we get the value from the left cell.
      And the final value is the OR of both the values

  • @SAHILOMATIC180
    @SAHILOMATIC180 8 лет назад

    why is their difference in regex and wildcard solution for pattern[i-1] = '*' for 0 occurance of character before '*'?

  • @chiragkhubdikar900
    @chiragkhubdikar900 2 года назад

    Example string: "xacyxay" and pattern "x?y" should return True right because the last three characters are a match, but using this approach it returns False. Or should it return False only?

    • @dominic_lee
      @dominic_lee 2 года назад

      ? can only be one character. x*y would match this though

  • @sukanyapai8984
    @sukanyapai8984 4 года назад

    Can you also explain the intuition behind why the formula for * and ? cases have come??

    • @anvesh687
      @anvesh687 4 года назад +1

      02:05 - exact reason behind the code

    • @sukanyapai8984
      @sukanyapai8984 4 года назад +1

      @@anvesh687 thanks

  • @silent_watchmen
    @silent_watchmen 8 лет назад

    Thank you very much Tushar, for the excellent video. However, I had a problem with your algorithm. If I implement with 2D array, it can't pass leetcode OJ (says memory limit exceeded). If I implement with 1D array, it says time limit exceeded. I used C++ and didn't see any extra code compared with your java code. Any thought?

    • @silent_watchmen
      @silent_watchmen 8 лет назад

      +Tushar Roy Thanks for reply and appreciate if you could take a look. Thanks. tinyurl.com/hrh8qj3

  • @siddharthkalani7535
    @siddharthkalani7535 3 года назад

    At 1:11 for pattern a*b string abc, why for this case it is false. * means there could be zero characters.
    Can you please explain this?

  • @ShaliniNegi24
    @ShaliniNegi24 4 года назад

    I am unable to understand when there is * mark what to do?

  • @anishsuman1371
    @anishsuman1371 3 года назад

    Why null string is not matched withs star in row 1

  • @cskcsk6370
    @cskcsk6370 6 лет назад

    The example mentioned initially is incorrect. For a pattern, a*b, a string "b" should be a match as we are looking for a string with 0 or more "a"s followed by a b.
    Otherwise a good video.

  • @prat534
    @prat534 5 лет назад

    Can we extend this logic to contain a delimiter character say '/' whose first instance does not map to '*' of any character ?

  • @abhishes
    @abhishes 6 лет назад

    Doesn't '?' mean that a is optional rather than "any 1 character between a and b"

  • @anshusharma11
    @anshusharma11 8 лет назад

    if (writeIndex > 0 && pattern[0] == '*')
    temp[0][1] = true;
    }
    +Tushar Roy please clerify : why we are not taking pattern[1]== '*' instead of looking for index 0. As index 0 is always a empty.

    • @anshusharma11
      @anshusharma11 8 лет назад +1

      Means index 0 always represent a empty character. So patter[0] contains null. So why we are checking patter[0]=='*'. Shouldn't we instead check pattern[1] == '*'
      please check at 5.08

    • @30harshal
      @30harshal 7 лет назад

      Hello, Anshu, I have the same doubt, did you find any explanation or solution further?. Reply me at Harshal Deolekar

  • @kitther
    @kitther 5 лет назад

    Hi, thanks for your video. It's the same excellent. Can I ask one question? Why do we need T[0][0], since there is no [0] letter in neither string nor pattern? Thanks.

    • @wensun510
      @wensun510 5 лет назад

      It will deal with situation when * represent empty string in the beginning. i.e s:abcd p:*abcd

    • @kitther
      @kitther 5 лет назад

      @@wensun510 I suppose the T[1] will include '*' if pattern has it in the beginning?

    • @wensun510
      @wensun510 5 лет назад

      @@kitther It would be harder to initialize T. i.e String:adc pattern: *a*c, When it comes to T[0][1], that's when you considering if a and *a is a match, you would want to refer to T[0-1][1] or T[0][1-1] according to the algorithm provided. Obviously referring to T[-1][1] would result in intdexOutOfBoundary exception. So you need to consider T[0][1] alone and initialize it and it would be harder. The initialization with empty char in the beginning would be a lot easier, you just have to make '*' match empty char that'll work.

    • @gulshanjangid3470
      @gulshanjangid3470 5 лет назад

      T[0][0] indicates when both the string and the pattern are empty. Which should return True

  • @rashmikiranpandit8962
    @rashmikiranpandit8962 4 года назад

    Thank you!

  • @asiskumarroy4470
    @asiskumarroy4470 4 года назад

    is this the same as the regular expression matching dp problem?

  • @balajiarumugam1876
    @balajiarumugam1876 5 лет назад +4

    what is difference between regular exp match and wildcard match?? pls explain me.

    • @anandtiwari1541
      @anandtiwari1541 5 лет назад +1

      in wildcard a* character - any 0 or more alphabet character. - a, ab, aa, ac, aaa
      in regular a* character - 0 more a character eg- empty, a, aa, aaa, aaaa this one can't be ab

  • @Shabnam_Bandyopadhyay
    @Shabnam_Bandyopadhyay 8 лет назад +1

    Hi Tushar , for input , patter= "ab*c" and string= "ac". this algorithm is returning false. though the pattern should accept ac .as it starts with a ends with c and zero occurrence of b. can you please clarify .

    • @404TimeOut
      @404TimeOut 8 лет назад +5

      I think you are confusing wildcard matching with regular expression matching. The meaning of * is different for wildcard and regex. In regex it means match 0 or more occurrences of the character in front of it, in your example, regex ab*c would match ac. But in wildcard matching, * means 0 or more characters, so ab*c would match a word that contains a, b, c, and have 0 or more characters between b and c, since ac does not contain b, it won't match. Wildcard matching is not the same as regular expression matching, though they sound very similar.

    • @vamsi54krishna
      @vamsi54krishna 6 лет назад

      false is expected answer as string "ac" doesn't have 'b' char which is required by pattern.

  • @winsterjose2574
    @winsterjose2574 4 года назад

    string -> abc & pattern -> a .. as per the logic, won't it return false ?

    • @winsterjose2574
      @winsterjose2574 4 года назад

      my mistake. It was clearly said in the beginning that, it is not a partial match rather complete one

  • @ankitgomkale11
    @ankitgomkale11 5 лет назад +1

    I think the condition for "*" is not correct. At 8:07, T[2][4] should be True as "xa" matches with "x?y*".

    • @addiegupta
      @addiegupta 5 лет назад

      how does xa match with x?y* ?

    • @ankitgomkale11
      @ankitgomkale11 5 лет назад

      @@addiegupta '?' can be replaced with any character. Let's say we replace it with 'a'. And '*' means zero or more repetition of previous character. Let's take zero repetition of 'y'. That leaves is with 'xa'.

  • @hyunjeongcho4037
    @hyunjeongcho4037 4 года назад

    thanks!

  • @s1337m
    @s1337m 7 лет назад

    What if a partial match was ok? how would the DP formula change?

  • @kamalsmusic
    @kamalsmusic 8 лет назад +4

    Also how do you do it with 1D array?

    • @Arunk054
      @Arunk054 7 лет назад

      Yes it is possible with just O(pattern) space complexity. See my solution here: gist.github.com/arunk054/f78091bf5e44ce5386a8035408a08377

    • @Arunk054
      @Arunk054 7 лет назад

      Btw.. Nice meeting you again @Kamal. Remember Microsoft 2016?

    • @vsg321
      @vsg321 6 лет назад +1

      You don't have to remember whole NxM matrix. You just need to remember the previous value on the left and one row of values above the current row.

  • @maharajak6578
    @maharajak6578 3 года назад

    no one talks about how the expression comes out first who needs people filling tables, show us how to get the idea for the expression

  • @maneshwarsingh8688
    @maneshwarsingh8688 4 года назад +1

    shouldn't T[1][2] be TRUE since we can replace the '?' with an empty string ""?

  • @innocent1029
    @innocent1029 6 лет назад

    awesome

  • @DhruvPatel-kg5ut
    @DhruvPatel-kg5ut 5 лет назад +2

    Why t[0][4] is false?

    • @shayanmalinda7409
      @shayanmalinda7409 5 лет назад

      It should be true no?

    • @vitaliistoian
      @vitaliistoian 5 лет назад

      You might be confused because * matches an empty string, however our pattern is not just *. T[0][4] is a match of empty string against the pattern x?y*, therefore it's not a match, so it's false.

  • @darshanbari2439
    @darshanbari2439 5 лет назад

    Tushar Roy and Adul Bari

  • @bantyK
    @bantyK 6 лет назад

    How did you derived the formula at 2:04 ?

  • @Null_pointer_exceptn
    @Null_pointer_exceptn 8 лет назад

    shouldnt "b" be true for a*b regex? i think it should be true as we can have 0 or more occurrence of a.

    • @Null_pointer_exceptn
      @Null_pointer_exceptn 8 лет назад

      Alright.Thanks.

    • @kitty_tax
      @kitty_tax 8 лет назад

      +Tushar Roy Thanks for the great video! For regex, the algorithm will remain same apart from some conditions (example - for regex a* - while matching the patter I need to go back 2 columns and check if condition True is possible or not), right?

  • @nlharish
    @nlharish 8 лет назад

    Shouldn't the condition in the code be "str[i] == pattern[j]" ?

    • @nlharish
      @nlharish 8 лет назад

      Nevermind. figured it out.

  • @sreetamaghosh1465
    @sreetamaghosh1465 Год назад

    leetcode's similar problem 44. Wildcard Matching,
    C++ code for the approach explain above :
    class Solution {
    // remove multiple * 's E.g : pc*** to pc*
    string remove (string p){
    bool first = true ;
    int j=0;
    for(int i=0;i

  • @xiaofeiguo2091
    @xiaofeiguo2091 8 лет назад

    why do you need to compress the multiple "*" into a single "*"?

    • @rajeshbajya6520
      @rajeshbajya6520 8 лет назад

      Every * represent 0 or more characters, So if you put ***** or * it will be same.