9.1 Knuth-Morris-Pratt KMP String Matching Algorithm

  • 🎬 Video
  • ℹ️ Description

In P3, b is also matching , lps should be 0 1 0 0 1 0 1 2 3 0

Naive Algorithm
Drawbacks of Naive Algorithm
Prefix and Suffix of Pattern
KMP Algorithm

Courses on Udemy
Java Programming

Data Structures using C and C++

C++ Programming

💬 Comments

Computer Science students will always be thankful to this legend ❤

Author — Usman Khan


this guy achieves to teach things in 20 minutes that university teachers fail to teach in hours

Author — Richárd Szegh


The best KMP algorithm explanation on YouTube.

Author — Luke Morrice


At 11:33 on pattern P3 aab should be 123 instead of 120

Author — Priyabrata


wish all these great tutorials were available when I was doing my graduation.

Author — Manish Kumawat


This man has singlehandedly helped me through so much of my undergrad degree. All for free. I can’t thank you enough Mr. Bari!

Author — Souvik Maiti


You teach me how to appreciate the beauty of algorithms.
Thank you so much.

Author — Chimao Lin


Mr Bari, you're truly a gem. None of the videos online could explain these concepts as clearly as you. Really appreciate what you are doing!

Author — tashfia shamim


As always my professor out here dropping gems on us humble students. Much love. We appreciate you

Author — P G.N


Thank you enormously from the Netherlands !

Author — Alexander Safi


You might have heard it many times, but still I prefer mentioning it that all these efforts you made to make such valuable contents free of cost is amazing, This is going to serve many programmers for the next coming years as well. Be it your way of explanation, your intuition every thing is just perfect. And we the programming community is thankful to you sir.

I do hope that you will be making more videos in the coming years. That is the only negative thing that I hear about this otherwise wonderful channel it that the advanced data structures and algorithms are not being covered. This is just a feedback from someone who has been following your videos for quiet a long time.

Again thank you sir

Author — Mamta Chahal


This is the best explanation I have ever seen. I have searched for several videos, most of them just focus on implementing without much reasoning. However, after watching this video, I fully understood the principle behind KMP and implemented the algorithm by myself. Thank you very much.

Author — guifan weng


Literally one of the best explainations of KMP on internet :) Keep it up sir.

Author — Shantanu Sharma


A very lucid explanation to a complex algorithm. Thank you very much sir.

Author — Itz Cs


Dude I love the video so much. When you found that last match it gave me a big smile. This algorithm is cool! You do such a great job explaining the concept. Thank you for the video.

Author — Zalgo the Destroyer


Sir, you should definitely create a bootcamp course for technical interviews, you ll save so many lives. Thank you for all your efforts sir !

Author — priya v


sir we absolutely love your videos, if you could pls include the algorithms for all these concepts too!

Author — Surabhi Sharma


Literally Sir You Are God, The Way You Teach is Just Beyond Imagination, Thankyou So Much For Making The Topic So Easy & Understandable.

Author — vansh varshney


You are awesome! Can you do video of Amortized analysis and loop invariant next time? I feel like these 2 topics are hard to understand

Author — Sharon Denys


Thank you.
It was hard to understand the Prefix and Suffix concepts in the context of String Pattern Matching, which was clarified easily.

Author — Anit Shrestha Manandhar