We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Substring Searching
Substring Searching
Sort by
recency
|
24 Discussions
|
Please Login in order to post a comment
scala:
Is it the same algortihm use for Model sailboats detection in sea?
The issue in Haskell is effectively making the table. This should be O(N) yet relies upon table queries being O(1), which they aren't utilizing records or even arrangements. In the end I concluded that one needed to go external the soul of Haskell, and seemingly utilitarian programming, and utilize a changeable cluster. check here
Scala solution works with prefix function as ArrayBuffer.
Description of pseudocode for the table-building algorithm in the Wikipedia link is not correct.
Correct algorithm can be found here https://cp-algorithms.com/string/prefix-function.html#implementation
Solution on Scala. It is based on Map ("indexedMap"). In which key is a char, which is present such in word and pat-candidate. And value is list of char order indexes. Each index is consistently incremented, when character of pat is found in word. For example, word "videobox" for pat "videobox" represented as ("v"->List(0), "i"->List(1),"d"->List(2),"e"->List(3),"0"->List(4,6),"b"->List(5),"x"->List(7)). Using this map, consistently compare indexes of pat-candidate with indexes of word in order to find the order. Order is detected, where the difference between indexes equals one (for example 6 and 5). If an order is detected for all characters in pat-candidate, pat is confirmed.