Z Algorithm Z values

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ต.ค. 2024

ความคิดเห็น • 146

  • @code-for-mars
    @code-for-mars ปีที่แล้ว +25

    even the paid course don't teach you with this much perfection hats off to tushar for this and many other videos like this .

  • @siddheshshinde4850
    @siddheshshinde4850 2 ปีที่แล้ว +19

    This video is absolutely perfect. Everything is explained very well from the fundamentals to the implementation part.

  • @shahinshahsavari1275
    @shahinshahsavari1275 3 ปีที่แล้ว +25

    I spent so much time trying to understand this from someone else's the source code. Watching this cleared up all my confusions. Thanks!

  • @yogeshyogesh8789
    @yogeshyogesh8789 8 ปีที่แล้ว +4

    Brother, I have started exploring String Algorithms few days back and , believe me , this is best resource I have found so far on the whole internet.

  • @Aditya-wj5gy
    @Aditya-wj5gy ปีที่แล้ว +1

    Thanks for such a wonderful explanation. This algo is one of the hardest as there are many variables you need to track and requires practice.

  • @Nikhil-ov6sm
    @Nikhil-ov6sm ปีที่แล้ว +1

    ok this is one of the few times where writing code is way more tougher than getting the logic..thanks btw great video

  • @sanketneema286
    @sanketneema286 5 หลายเดือนก่อน

    Tushar is a saver, it looks like other TH-camrs also watch Tushar's videos to clear their doubts.

  • @satviktejas6085
    @satviktejas6085 ปีที่แล้ว

    One of the best explanation available on internet

  • @saurabhsharma7123
    @saurabhsharma7123 7 ปีที่แล้ว +6

    String Theory has always been a mystery for me until just now!Cannot thank you more !

    • @shreyjain51
      @shreyjain51 4 ปีที่แล้ว +10

      This is not called "String Theory"!!! That is a branch of physics.

    • @genuineprofile6400
      @genuineprofile6400 ปีที่แล้ว +3

      It's still is a mystery to you and other physicists.

  • @shekhar3027
    @shekhar3027 8 ปีที่แล้ว +2

    wow..!!
    Thanks alot Tushar..!!
    Your tutorials are always informative and are in detail. But the best part is that its easily explained and extremely easy to understand and implement...
    :)...

  • @aashutoshagrawal5239
    @aashutoshagrawal5239 11 วันที่ผ่านมา

    Loved the explanation.. Thank you for the video.

  • @abhisheksharma7056
    @abhisheksharma7056 2 ปีที่แล้ว +1

    we can use even lps(longest prefix suffix) array of appended string to find out the index of matching

  • @keilamartinez7394
    @keilamartinez7394 4 ปีที่แล้ว +5

    Absolutely great! You made it very easy to understand the algorithm, thank you so much!!

  • @omprakashsharma9767
    @omprakashsharma9767 4 ปีที่แล้ว

    I always like your videos, to the point no time wasting.

  • @AGENTxxFURY
    @AGENTxxFURY 11 หลายเดือนก่อน

    Best explanation , awesome teacher !!!

  • @malharjajoo7393
    @malharjajoo7393 7 ปีที่แล้ว

    +Tushar Roy -great explanation as usual , clearly shows how well you understand.

  • @shuangli5466
    @shuangli5466 ปีที่แล้ว

    excellent explaination, I understood it instantly

  • @marcolunardi3630
    @marcolunardi3630 3 หลายเดือนก่อน +1

    Excelent video, helped a lot

    • @MrDirtzuke
      @MrDirtzuke 3 หลายเดือนก่อน +1

      true

  • @shubhamk840
    @shubhamk840 4 ปีที่แล้ว

    best video tutorial amazing Mr. Tushar.

  • @saqibmasood501
    @saqibmasood501 3 หลายเดือนก่อน

    Nicely explained

  • @tahanimachowdhury
    @tahanimachowdhury 8 ปีที่แล้ว +8

    Thanks a ton :D Waiting for Aho - Corasick and Finite State Automation :D

    • @Shawn9081
      @Shawn9081 8 ปีที่แล้ว +5

      8 months later im still alive but no video ;'{

    • @adhishmalviya2408
      @adhishmalviya2408 4 ปีที่แล้ว +5

      4 years later, NO video

    • @muthojusaketh
      @muthojusaketh 3 ปีที่แล้ว

      4yrs 10 months later, no video :(

    • @jotsinghbindra8317
      @jotsinghbindra8317 4 หลายเดือนก่อน +1

      8years now still no video

  • @sanjeevacham2400
    @sanjeevacham2400 8 ปีที่แล้ว

    Excellent Tushar , you done it again.

  • @smartwork7098
    @smartwork7098 หลายเดือนก่อน

    Beautiful man.
    Edit: Beautiful explanation, man

  • @shivampratapsingh2188
    @shivampratapsingh2188 5 หลายเดือนก่อน

    Amazing explaination !!11

  • @sgerodes
    @sgerodes 6 ปีที่แล้ว +1

    Awesome explanation. Thank you very much

  • @aniketsriwastva6345
    @aniketsriwastva6345 4 ปีที่แล้ว

    Great Explaination Sir

  • @pramodprajapati9166
    @pramodprajapati9166 6 ปีที่แล้ว +2

    Great Job as Always. I did understood the Algorithm instantly, but struggled in the implementation. Can you give any tips to improve on the implementation part. Maybe something I need to do or something I might be doing wrong.

  • @vijay_lakra
    @vijay_lakra 9 ปีที่แล้ว

    Very good explanation.Thanks Tushar.

  • @udaysabbisetty9509
    @udaysabbisetty9509 ปีที่แล้ว

    Man!!!That's Amazing Explaination...Thank You:)

  • @cm30tanaykulkarni14
    @cm30tanaykulkarni14 3 ปีที่แล้ว

    INFORMATIVE

  • @savanmatariya7494
    @savanmatariya7494 3 ปีที่แล้ว

    Well Explained!!, Keep it up

  • @ketan_sahu
    @ketan_sahu 3 ปีที่แล้ว

    Great explanation. Thanks!

  • @gandhijainamgunvantkumar6783
    @gandhijainamgunvantkumar6783 2 ปีที่แล้ว

    Amazing explanation 😀

  • @Nate-kw9by
    @Nate-kw9by 7 หลายเดือนก่อน

    Great tutorial!

  • @glaucoa.9214
    @glaucoa.9214 3 ปีที่แล้ว

    Thanks alot Tushar..!!

  • @KanagaveluSugumar
    @KanagaveluSugumar 8 ปีที่แล้ว +1

    Wow! you have done a great job :) And is that reusing match count within the Z box is benefit will i get compare to brute force ?? if not how it is better than brute force ?

  • @ankitkumar-et8ew
    @ankitkumar-et8ew 5 ปีที่แล้ว +1

    What happens if parent string is 'aaaaa' and we have to calculate the no. Of comparison then it should be 4+3+2+1 or we can say it is of the form n+n-1+n-2+....1 therefore it's complexity is On^2

  • @malharjajoo7393
    @malharjajoo7393 7 ปีที่แล้ว

    +Tushar Roy - your explanation is great , but it would be really good if you can give some context about the algorithm , like how difficult it is , etc.

  • @ankitm511
    @ankitm511 6 ปีที่แล้ว

    Nice explanation :) Very easy to understand compared to reading about it

  • @quyenamba4556
    @quyenamba4556 8 ปีที่แล้ว +1

    It's very helpful and easy to understand :D Thanks u so much

  • @srijonmuhtasim3669
    @srijonmuhtasim3669 3 ปีที่แล้ว

    helped a lot to understand the concept

  • @ningwang8077
    @ningwang8077 8 ปีที่แล้ว

    you help me a lot, hope you upload more videos and I will always follow your channel~

  • @DeepakKumar-wu4dt
    @DeepakKumar-wu4dt 4 ปีที่แล้ว

    Really Helpful . Thanks

  • @venkatnarasimha1317
    @venkatnarasimha1317 8 ปีที่แล้ว

    Excellent tutorial. I have one question to ask. Why should we prepend the pattern to the string. Instead we can also compare while it is a different string

  • @KittyMaheshwari
    @KittyMaheshwari 2 ปีที่แล้ว

    Excellent!

  • @sarthakbansal1303
    @sarthakbansal1303 4 ปีที่แล้ว

    Great explanation !!!

  • @fruith_
    @fruith_ 2 ปีที่แล้ว

    Thankiu. Hope to wacth multiple matrix

  • @saurabhv1
    @saurabhv1 8 ปีที่แล้ว +2

    What if the main string can consist of any utf8 character ?
    How to choose a special character in such a case ?

  • @martokalinov3733
    @martokalinov3733 ปีที่แล้ว +1

    Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:)

  • @CryingMG
    @CryingMG 9 ปีที่แล้ว

    Great tutorial as always.
    Good job!

  • @harshitgangwar1426
    @harshitgangwar1426 4 ปีที่แล้ว

    Good Job Brother.

  • @ScramblerUSA
    @ScramblerUSA 8 ปีที่แล้ว +8

    Honestly, it's not right. When you copy the values from Z-box to Z-box, you make a comparison for every number to find out whether it falls beyond the right boundary or not. Why these comparisons are not accounted for?

    • @deepankarsingh7230
      @deepankarsingh7230 8 ปีที่แล้ว

      I am also wondering why its not counted in this video. Probably if we count that too, it should not go beyond linear time. But what will be the proof of that??

    • @sundeepb
      @sundeepb 8 ปีที่แล้ว +1

      Yes, they should be counted, but that still makes the algorithm in linear time because when it falls in the right bounds, we will just copy the count, saving multiple comparisons from the first time. When it is out of bounds, we are going beyond the Z box, making new comparisons.

    • @pramodprajapati9166
      @pramodprajapati9166 6 ปีที่แล้ว

      I think you are confused here because of the while in the for loop. Watchout that the while comparison is known and withing the Bounds (i.e 0-Left and R to Length at most). So it will not be n^2 complexity. If the while comparison was from 0 to N then it will be n^2

  • @ninhtrinh8536
    @ninhtrinh8536 3 ปีที่แล้ว

    Thank you very much !

  • @dronelektron
    @dronelektron 9 ปีที่แล้ว +1

    As always great

  • @vedicdutta2856
    @vedicdutta2856 4 หลายเดือนก่อน

    Awesome!

  • @ChinmayTerse
    @ChinmayTerse 8 ปีที่แล้ว +4

    Minor issue at 11:48 shouldn't it be greater than or equal to 1? Great video though!

    • @pawantiwary2043
      @pawantiwary2043 8 ปีที่แล้ว

      what is the condition used at this timestamp? I did not understand. Could you please exlain?

    • @pranaykanjolia9077
      @pranaykanjolia9077 4 ปีที่แล้ว

      Yaa, it should be greater than or equal to 1

  • @sheetal831
    @sheetal831 8 ปีที่แล้ว +1

    Thanks alot bro!!! Such a great explanation of the algorithm :)

  • @Kupo3.0
    @Kupo3.0 ปีที่แล้ว

    Thank you!

  • @sauravsingh7216
    @sauravsingh7216 4 ปีที่แล้ว

    Awesome bro.....,

  • @nwanzefranklin7777
    @nwanzefranklin7777 9 ปีที่แล้ว

    thanks a lot tushar, it really helped

  • @BenevolentKhalluudi
    @BenevolentKhalluudi 8 ปีที่แล้ว +1

    Really great explanation. Thank you very much for the effort to explain it clearly!

  • @edelfrefloresmamani4562
    @edelfrefloresmamani4562 4 ปีที่แล้ว

    nice explanation :)

  • @durgeshdeep2544
    @durgeshdeep2544 9 ปีที่แล้ว

    Thanks Tushar

  • @singhalvikash
    @singhalvikash 7 ปีที่แล้ว +1

    Hey Tushar ,
    Great videos and explanation . Keep up the good work !
    Do you have a video tutorial created for Sliding Window algorithm as well ?

  • @edwardnjoroge5222
    @edwardnjoroge5222 3 ปีที่แล้ว

    You rock! Thank you!

  • @prashantkaushal4057
    @prashantkaushal4057 11 หลายเดือนก่อน

    at 21:04 time it will go the if condition because k is not greater than right but it is equal to right

  • @dineshkumar-kz3nc
    @dineshkumar-kz3nc 4 ปีที่แล้ว +1

    good explation of algorithm and code both. Generally doesn't find the code explanation easily so good job.
    I guess all u need to improve that use something much digital and clear then this white board that's all.

  • @anurag6219
    @anurag6219 2 ปีที่แล้ว

    AHHH NICE EXPLANATIONS !!!!!

  • @gal1l1l-f7c
    @gal1l1l-f7c 9 ปีที่แล้ว +1

    Thanks Tushar, great video! :) Can you explain Aho-Corasick in another one?

  • @jithinbabu6902
    @jithinbabu6902 4 ปีที่แล้ว

    Thank you for the great explanation. I have one doubt though. We can do this algorithm even without $ right?

    • @francineidesilva5310
      @francineidesilva5310 4 ปีที่แล้ว

      vhx.n ,o

    • @madhankumar8463
      @madhankumar8463 2 ปีที่แล้ว

      No, there is a chance that the pattern maybe formed when we join the pattern and string.

  • @juzhengzhang3059
    @juzhengzhang3059 3 ปีที่แล้ว

    Should Z[0] = the length of original string?

  • @markjethropacheco4546
    @markjethropacheco4546 4 หลายเดือนก่อน

    I don`t understand the O(m+n) part. I don`t understand its purpose.

  • @subtlechords
    @subtlechords 3 ปีที่แล้ว

    Thankyou so much

  • @ranganroy8494
    @ranganroy8494 3 ปีที่แล้ว

    on 11:16 when on index 13 the value of the Z array is 5, then 13+15 is crossing our Z box by 1 index. So, why we are not recalculating it again?

    • @ranganroy8494
      @ranganroy8494 3 ปีที่แล้ว

      It will be great if anyone could help me out with this.

  • @mohit7717
    @mohit7717 2 ปีที่แล้ว

    For user input how i will know that special character are not exist in the input given by user ? How can we solve this problem

  • @Vicky-pu5fw
    @Vicky-pu5fw 8 ปีที่แล้ว +1

    sir please upload video of TRIE/ Prefix tree

  • @imyashdeepsharma
    @imyashdeepsharma 9 ปีที่แล้ว

    Awesome algorithm sir :)

    • @imyashdeepsharma
      @imyashdeepsharma 9 ปีที่แล้ว +1

      +Tushar Roy Please post LCA Queries sir

  • @grev7794
    @grev7794 7 ปีที่แล้ว

    thank you :) very helpful

  • @biboswanroy6699
    @biboswanroy6699 4 ปีที่แล้ว

    I'm your fan now

  • @hAsH_learn2code
    @hAsH_learn2code 3 ปีที่แล้ว

    Thank you

  • @somesome1315
    @somesome1315 3 ปีที่แล้ว

    helpful thx

  • @sarwarjahan05
    @sarwarjahan05 8 ปีที่แล้ว +1

    Can i make table like kmp for z (pattern+$+text)?

  • @omaryasser2308
    @omaryasser2308 8 ปีที่แล้ว

    Thank you very much. :)

  • @gigelfranaru
    @gigelfranaru 7 ปีที่แล้ว

    But why not just use a for that goes along the main text and looks for the pattern chars in sequence, and when a mismatch occurs, reset the index of where to look into in the pattern string. Why do all this work ?

    • @danielmitre
      @danielmitre 7 ปีที่แล้ว +1

      The index you are in the sequence have to reset to previous+1, so it is O(n²) time complexity

  • @rohitraj4394
    @rohitraj4394 5 ปีที่แล้ว

    how you will compute Z Array for
    Pattern P = caca and String = cacacacacacacacacaca. Please explain.

  • @SNM_23745
    @SNM_23745 3 ปีที่แล้ว

    thank you

  • @bishyankar2388
    @bishyankar2388 8 ปีที่แล้ว

    Scanner sc=new Scanner(System.in);
    String s=sc.next();
    String s1=sc.next();
    int i;
    for(i=0;i

    • @bishyankar2388
      @bishyankar2388 8 ปีที่แล้ว

      i tried it codechef

    • @bishyankar2388
      @bishyankar2388 8 ปีที่แล้ว

      how are you calculating the time complexity

    • @bishyankar2388
      @bishyankar2388 8 ปีที่แล้ว

      mine

    • @elllot_
      @elllot_ 7 ปีที่แล้ว +4

      You do realize this is a O(m*n) (O(m*(n-m) to be exact) comparison where m is the length of the pattern and n is the length of the string algorithm compared to Z algorithm's O(n) complexity right? You're doing a comparison for the full pattern at each index. I do not buy your statement that this performed better than the Z algorithm. I think you should double check your implementation of the Z algorithm

  • @lonandon
    @lonandon 3 ปีที่แล้ว

    When to use Z Algorithm and when to use KMP?

  • @pawantiwary2043
    @pawantiwary2043 8 ปีที่แล้ว

    Thanks for this video but I did not understand at 11:48...Could you (or any one)please explain this condition?

    • @mishramadhur
      @mishramadhur 8 ปีที่แล้ว +1

      At this time stamp, we are at index 17 now since this character is in Z-box(notation used in video) we want to take its value from the previous position i.e from index 4, if we take its value 4 from the previous index(4), it means that a prefix of length 4 of the original string matches the suffix starting at index 17, but since the total length of string is only 18, the value can't be 4, since the suffix starting at index 17 can be of length 1 only.
      Hence the value is min(prev_value_taken, remaining length) i.e min(4, 18-17) = 1.
      Hope it helps

  • @mujahidansorimajid1524
    @mujahidansorimajid1524 3 ปีที่แล้ว

    what if my pattern or my text the '$' exist will the code still work fine?

  • @timothyfield6190
    @timothyfield6190 8 ปีที่แล้ว

    Very Helpful! Thank you.

  • @Inotaku
    @Inotaku 3 ปีที่แล้ว

    why we need the line right--; ?

  • @shreyjain51
    @shreyjain51 4 ปีที่แล้ว

    He made a mistake at 10:04. It is not 17, it is 16.

  • @ritikbansal4851
    @ritikbansal4851 4 ปีที่แล้ว

    Can anyone explain to me why do we do right - - in calculatez function.
    Thanks in advance

  • @fruith_
    @fruith_ 2 ปีที่แล้ว

    Hope you reply, but if it's not, it's okay

  • @rahukdubey8138
    @rahukdubey8138 3 ปีที่แล้ว

    while watching this video my brother (small haldi bilauwa) was beating me

  • @ep.jonnadula
    @ep.jonnadula 8 ปีที่แล้ว

    plz speak at normal speed at starting of video.every thing else is too good

  • @duydangdroid
    @duydangdroid 7 ปีที่แล้ว +1

    12:01
    char[18] should be compared to char[5], not char[1]

    • @deepalikhalkar1880
      @deepalikhalkar1880 6 ปีที่แล้ว +1

      Duy Dang correct

    • @satishkumarpatra4896
      @satishkumarpatra4896 5 ปีที่แล้ว

      That's why he used l and r to specify where he can directly write or not. He did it
      correctly.

  • @Glyra12
    @Glyra12 7 ปีที่แล้ว

    great tutorial! would you mind putting subtitles, tho? xD

    • @malharjajoo7393
      @malharjajoo7393 7 ปีที่แล้ว +6

      the guy probably speaks better than you

  • @yuvraj2038
    @yuvraj2038 2 ปีที่แล้ว

    Who is here after today's Leetcode contest?