BF and KMP algorithm