Understanding the prefix function in KMP

Report a typo
Hey there! This problem might be a bit unpredictable, but give it a go and let us know how you do!
The following code snippet shows a function that calculates the prefix function for a string. Identify the correct statements about this function and its relation to substring searching.
def prefix_function(pattern):
    prefix = [0]*len(pattern)
    j = 0
    for i in range(1,len(pattern)):
        while j > 0 and pattern[i] != pattern[j]:
            j = prefix[j-1]
        if pattern[i] == pattern[j]:
            j += 1
        prefix[i] = j
    return prefix
Select one or more options from the list
___

Create a free account to access the full topic