Z Algorithm Z values

  Рет қаралды 162,128

Tushar Roy - Coding Made Simple

Tushar Roy - Coding Made Simple

Күн бұрын

Пікірлер: 146
@code-for-mars
@code-for-mars Жыл бұрын
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 жыл бұрын
This video is absolutely perfect. Everything is explained very well from the fundamentals to the implementation part.
@shahinshahsavari1275
@shahinshahsavari1275 4 жыл бұрын
I spent so much time trying to understand this from someone else's the source code. Watching this cleared up all my confusions. Thanks!
@Nikhil-ov6sm
@Nikhil-ov6sm Жыл бұрын
ok this is one of the few times where writing code is way more tougher than getting the logic..thanks btw great video
@satviktejas6085
@satviktejas6085 Жыл бұрын
One of the best explanation available on internet
@sanketneema286
@sanketneema286 6 ай бұрын
Tushar is a saver, it looks like other KZbinrs also watch Tushar's videos to clear their doubts.
@Aditya-wj5gy
@Aditya-wj5gy Жыл бұрын
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.
@yogeshyogesh8789
@yogeshyogesh8789 8 жыл бұрын
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.
@abhisheksharma7056
@abhisheksharma7056 3 жыл бұрын
we can use even lps(longest prefix suffix) array of appended string to find out the index of matching
@aashutoshagrawal5239
@aashutoshagrawal5239 2 ай бұрын
Loved the explanation.. Thank you for the video.
@shubhamk840
@shubhamk840 4 жыл бұрын
best video tutorial amazing Mr. Tushar.
@AGENTxxFURY
@AGENTxxFURY Жыл бұрын
Best explanation , awesome teacher !!!
@saurabhsharma7123
@saurabhsharma7123 7 жыл бұрын
String Theory has always been a mystery for me until just now!Cannot thank you more !
@shreyjain51
@shreyjain51 4 жыл бұрын
This is not called "String Theory"!!! That is a branch of physics.
@genuineprofile6400
@genuineprofile6400 2 жыл бұрын
It's still is a mystery to you and other physicists.
@shuangli5466
@shuangli5466 Жыл бұрын
excellent explaination, I understood it instantly
@sanjeevacham2400
@sanjeevacham2400 9 жыл бұрын
Excellent Tushar , you done it again.
@omprakashsharma9767
@omprakashsharma9767 4 жыл бұрын
I always like your videos, to the point no time wasting.
@vijay_lakra
@vijay_lakra 9 жыл бұрын
Very good explanation.Thanks Tushar.
@malharjajoo7393
@malharjajoo7393 7 жыл бұрын
+Tushar Roy -great explanation as usual , clearly shows how well you understand.
@keilamartinez7394
@keilamartinez7394 4 жыл бұрын
Absolutely great! You made it very easy to understand the algorithm, thank you so much!!
@tahanimachowdhury
@tahanimachowdhury 9 жыл бұрын
Thanks a ton :D Waiting for Aho - Corasick and Finite State Automation :D
@Shawn9081
@Shawn9081 8 жыл бұрын
8 months later im still alive but no video ;'{
@adhishmalviya2408
@adhishmalviya2408 4 жыл бұрын
4 years later, NO video
@muthojusaketh
@muthojusaketh 3 жыл бұрын
4yrs 10 months later, no video :(
@jotsinghbindra8317
@jotsinghbindra8317 5 ай бұрын
8years now still no video
@smartwork7098
@smartwork7098 2 ай бұрын
Beautiful man. Edit: Beautiful explanation, man
@sgerodes
@sgerodes 6 жыл бұрын
Awesome explanation. Thank you very much
@marcolunardi3630
@marcolunardi3630 4 ай бұрын
Excelent video, helped a lot
@MrDirtzuke
@MrDirtzuke 4 ай бұрын
true
@shekhar3027
@shekhar3027 8 жыл бұрын
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... :)...
@udaysabbisetty9509
@udaysabbisetty9509 2 жыл бұрын
Man!!!That's Amazing Explaination...Thank You:)
@shivampratapsingh2188
@shivampratapsingh2188 7 ай бұрын
Amazing explaination !!11
@aniketsriwastva6345
@aniketsriwastva6345 4 жыл бұрын
Great Explaination Sir
@saqibmasood501
@saqibmasood501 5 ай бұрын
Nicely explained
@gandhijainamgunvantkumar6783
@gandhijainamgunvantkumar6783 2 жыл бұрын
Amazing explanation 😀
@ankitm511
@ankitm511 6 жыл бұрын
Nice explanation :) Very easy to understand compared to reading about it
@prashantkaushal4057
@prashantkaushal4057 Жыл бұрын
at 21:04 time it will go the if condition because k is not greater than right but it is equal to right
@savanmatariya7494
@savanmatariya7494 3 жыл бұрын
Well Explained!!, Keep it up
@quyenamba4556
@quyenamba4556 8 жыл бұрын
It's very helpful and easy to understand :D Thanks u so much
@pramodprajapati9166
@pramodprajapati9166 6 жыл бұрын
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.
@fruith_
@fruith_ 2 жыл бұрын
Thankiu. Hope to wacth multiple matrix
@ankitkumar-et8ew
@ankitkumar-et8ew 5 жыл бұрын
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
@KanagaveluSugumar
@KanagaveluSugumar 8 жыл бұрын
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 ?
@cm30tanaykulkarni14
@cm30tanaykulkarni14 3 жыл бұрын
INFORMATIVE
@ningwang8077
@ningwang8077 8 жыл бұрын
you help me a lot, hope you upload more videos and I will always follow your channel~
@glaucoa.9214
@glaucoa.9214 3 жыл бұрын
Thanks alot Tushar..!!
@saurabhv1
@saurabhv1 8 жыл бұрын
What if the main string can consist of any utf8 character ? How to choose a special character in such a case ?
@Nate-kw9by
@Nate-kw9by 9 ай бұрын
Great tutorial!
@ketan_sahu
@ketan_sahu 3 жыл бұрын
Great explanation. Thanks!
@srijonmuhtasim3669
@srijonmuhtasim3669 3 жыл бұрын
helped a lot to understand the concept
@DeepakKumar-wu4dt
@DeepakKumar-wu4dt 4 жыл бұрын
Really Helpful . Thanks
@harshitgangwar1426
@harshitgangwar1426 4 жыл бұрын
Good Job Brother.
@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.
@venkatnarasimha1317
@venkatnarasimha1317 9 жыл бұрын
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
@sarthakbansal1303
@sarthakbansal1303 4 жыл бұрын
Great explanation !!!
@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
@KittyMaheshwari
@KittyMaheshwari 2 жыл бұрын
Excellent!
@ChinmayTerse
@ChinmayTerse 8 жыл бұрын
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
@BenevolentKhalluudi
@BenevolentKhalluudi 8 жыл бұрын
Really great explanation. Thank you very much for the effort to explain it clearly!
@sheetal831
@sheetal831 8 жыл бұрын
Thanks alot bro!!! Such a great explanation of the algorithm :)
@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.
@juzhengzhang3059
@juzhengzhang3059 3 жыл бұрын
Should Z[0] = the length of original string?
@dronelektron
@dronelektron 9 жыл бұрын
As always great
@Vicky-pu5fw
@Vicky-pu5fw 8 жыл бұрын
sir please upload video of TRIE/ Prefix tree
@sauravsingh7216
@sauravsingh7216 4 жыл бұрын
Awesome bro.....,
@nwanzefranklin7777
@nwanzefranklin7777 9 жыл бұрын
thanks a lot tushar, it really helped
@markjethropacheco4546
@markjethropacheco4546 6 ай бұрын
I don`t understand the O(m+n) part. I don`t understand its purpose.
@ScramblerUSA
@ScramblerUSA 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 жыл бұрын
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
@CryingMG
@CryingMG 9 жыл бұрын
Great tutorial as always. Good job!
@biboswanroy6699
@biboswanroy6699 4 жыл бұрын
I'm your fan now
@edelfrefloresmamani4562
@edelfrefloresmamani4562 4 жыл бұрын
nice explanation :)
@dineshkumar-kz3nc
@dineshkumar-kz3nc 4 жыл бұрын
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.
@kaal_bhairav_24
@kaal_bhairav_24 4 жыл бұрын
13:24 here we go digital
@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 жыл бұрын
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
@ninhtrinh8536
@ninhtrinh8536 3 жыл бұрын
Thank you very much !
@mujahidansorimajid1524
@mujahidansorimajid1524 3 жыл бұрын
what if my pattern or my text the '$' exist will the code still work fine?
@imyashdeepsharma
@imyashdeepsharma 9 жыл бұрын
Awesome algorithm sir :)
@imyashdeepsharma
@imyashdeepsharma 9 жыл бұрын
+Tushar Roy Please post LCA Queries sir
@singhalvikash
@singhalvikash 7 жыл бұрын
Hey Tushar , Great videos and explanation . Keep up the good work ! Do you have a video tutorial created for Sliding Window algorithm as well ?
@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.
@Inotaku
@Inotaku 3 жыл бұрын
why we need the line right--; ?
@anurag6219
@anurag6219 2 жыл бұрын
AHHH NICE EXPLANATIONS !!!!!
@lonandon
@lonandon 3 жыл бұрын
When to use Z Algorithm and when to use KMP?
@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 жыл бұрын
The index you are in the sequence have to reset to previous+1, so it is O(n²) time complexity
@martokalinov3733
@martokalinov3733 Жыл бұрын
Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:)
@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 жыл бұрын
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
@sarwarjahan05
@sarwarjahan05 8 жыл бұрын
Can i make table like kmp for z (pattern+$+text)?
@gal1l1l-f7c
@gal1l1l-f7c 9 жыл бұрын
Thanks Tushar, great video! :) Can you explain Aho-Corasick in another one?
@durgeshdeep2544
@durgeshdeep2544 9 жыл бұрын
Thanks Tushar
@rohitraj4394
@rohitraj4394 6 жыл бұрын
how you will compute Z Array for Pattern P = caca and String = cacacacacacacacacaca. Please explain.
@vedicdutta2856
@vedicdutta2856 6 ай бұрын
Awesome!
@subtlechords
@subtlechords 3 жыл бұрын
Thankyou so much
@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
@ritikbansal4851
@ritikbansal4851 4 жыл бұрын
Can anyone explain to me why do we do right - - in calculatez function. Thanks in advance
@shreyjain51
@shreyjain51 4 жыл бұрын
He made a mistake at 10:04. It is not 17, it is 16.
@SNM_23745
@SNM_23745 3 жыл бұрын
thank you
@edwardnjoroge5222
@edwardnjoroge5222 3 жыл бұрын
You rock! Thank you!
@somesome1315
@somesome1315 3 жыл бұрын
helpful thx
@grev7794
@grev7794 8 жыл бұрын
thank you :) very helpful
@duydangdroid
@duydangdroid 7 жыл бұрын
12:01 char[18] should be compared to char[5], not char[1]
@deepalikhalkar1880
@deepalikhalkar1880 6 жыл бұрын
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.
@timothyfield6190
@timothyfield6190 8 жыл бұрын
Very Helpful! Thank you.
@yuvraj2038
@yuvraj2038 2 жыл бұрын
Who is here after today's Leetcode contest?
@FelipeRodrigues-lj1el
@FelipeRodrigues-lj1el 8 жыл бұрын
Thank you!
@omaryasser2308
@omaryasser2308 8 жыл бұрын
Thank you very much. :)
@ep.jonnadula
@ep.jonnadula 8 жыл бұрын
plz speak at normal speed at starting of video.every thing else is too good
@hAsH_learn2code
@hAsH_learn2code 3 жыл бұрын
Thank you
@jesperat
@jesperat 5 жыл бұрын
he sounds really angry.
Longest Palindromic Substring Manacher's Algorithm
16:46
Tushar Roy - Coding Made Simple
Рет қаралды 343 М.
Knuth-Morris-Pratt(KMP) Pattern Matching(Substring search)
12:50
Tushar Roy - Coding Made Simple
Рет қаралды 1,1 МЛН
This Game Is Wild...
00:19
MrBeast
Рет қаралды 199 МЛН
How To Choose Mac N Cheese Date Night.. 🧀
00:58
Jojo Sim
Рет қаралды 107 МЛН
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 593 М.
Skyline Problem
22:54
Tushar Roy - Coding Made Simple
Рет қаралды 194 М.
Lowest Common Ancestor Binary Tree
11:08
Tushar Roy - Coding Made Simple
Рет қаралды 252 М.
2 Years of C++ Programming
8:20
Zyger
Рет қаралды 10 М.
9.1 Knuth-Morris-Pratt KMP String Matching Algorithm
18:56
Abdul Bari
Рет қаралды 1,7 МЛН
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 675 М.
16. Strings
1:24:30
MIT OpenCourseWare
Рет қаралды 126 М.
Morris Inorder Tree Traversal
11:44
Tushar Roy - Coding Made Simple
Рет қаралды 147 М.
9.2 Rabin-Karp String Matching Algorithm
23:50
Abdul Bari
Рет қаралды 827 М.
This Game Is Wild...
00:19
MrBeast
Рет қаралды 199 МЛН