Cool, it's a clever move. It will solve the scenarios where the string length is larger than 256 (assume the char set is ASCII). You will still need to do some necessary work for the case of string length less than 256. That was a solution without using extra memory. KMP is great when you already have two strings, while in this case, what you've got are two trees (need extra memory to convert them into strings) and the data might not be characters.