▲ | lokeg 5 days ago | |||||||
What about the worst case? I.e. something like searching for 1000 'a's in a long string of 'a's interspersed with 'b's every 500-1000 steps? Seems accidentally quadradic unfortunately in the absence of some KMP-like fallback | ||||||||
▲ | MattPalmer1086 5 days ago | parent | next [-] | |||||||
Worst case for these types of search is O(mn), m length of needle, n length of haystack. It is not linear in n. The absolute worst case is when both the needle and haystack are both composed of the same byte repeated (e.g. all zero). | ||||||||
▲ | expenses3 5 days ago | parent | prev [-] | |||||||
How is it quadratic? You do 1000 checks every character in the haystack but that's still O(n) | ||||||||
|