Algorithms for quickly approximating strings

Given the source line sand nlines of equal length, I need to find a quick algorithm to return those lines that have no more kcharacters than the original line sfor each corresponding position.

What is a fast algorithm for this?

PS: I have to argue that this is a question academic. I want to find the most efficient algorithm, if possible.

I also missed one very important information. Lines of equal length nform a dictionary against which many source lines will be queried s. There seems to be some kind of preprocessing step to make it more efficient.

+2
source share
5 answers

My gut instinct is simply to iterate over each line n, maintaining a count of the number of characters other than s, but I do not claim that this is the most effective solution. However, this will be O (n), so if this is not a known performance issue or an academic issue, I would go with that.

+2
source
+2
source

, , , ; O (n) . , O (nm) m .

, , , - ; - (p, c), p - , c - , - , ( "the" {(0, 't'), "the" }, {(1, h '), "the" }, {(2,' e '), "the" }). , ; - , - , ( "the" "" 2, "tee" 1). , , K.

, , K, . , K 5, N 8, , 4-8 , , , 5 . , 6- , , 3.

, NoSql - , ( , ).

, (p, c) , ( (5, 't') "5t" (12, 'x') "12x" ).

+1

, , , . - . i - , false, i == k true, k-i .

, , , , , , , . , , .

0

, : P , n, , . , n, .

, n n' s s'.

s' , n', s'. n' s', n'. . , k n .

For further consideration, added preprocessing can be performed for each adjacent line in nto see the total number of characters that differ. This could be used when comparing strings nand s, and if nthere is enough difference between them and the neighboring one, maybe there is no need to compare it?

0
source

All Articles