It's O(n). I find this video a better explanation of KMP since it goes over more examples and how to calculation the failure function in depth. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-GTJr8OvyEVQ.html
Right, it should be "j = j + 1" and not "j + j + 1". I think that the mistake is small enough and obvious enough that the people will understand. Thanks for helping.