D
D
Dmitry Gavrilenko2016-12-19 18:05:06
.NET
Dmitry Gavrilenko, 2016-12-19 18:05:06

Algorithm for finding a pattern in an unordered sequence?

Welcome all.
The task is that: there is not sorted (naturally) an array of bytes of dimension 2 and more.
There is a certain pattern with a size of 10 bytes. We need to find all positions of the pattern in the array.
Linear search is not the best implementation. Tell me which is faster.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
x67, 2016-12-19
@Maddox

Well, in general, as Alexander noted , you want a miracle, but the algorithm can be optimized if there is any pattern that allows you to predict in which areas the desired pattern can be.
Also, if the location of the beginning of the pattern cannot be arbitrary (that is, the pattern can start at 1, 11, 21 bytes, but cannot start at 37 for example), then the search time can be reduced by less than 10 times by first searching all the first bytes , and then checking these places already completely.
You can also look for a pattern in this pattern.
But in general, if this is going to be a regular task, screw in something for the initial processing of the array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question