D
D
daniel12014-10-31 20:02:53
C++ / C#
daniel1, 2014-10-31 20:02:53

What is the most efficient way to check for occurrence of a sequence in an array?

Hello. I have a task - to find a sequence in an array. Let's say there is an array a={x,y,z,...} and an array b={x,y}. We need to check if array b is contained in a. What algorithm will be the most efficient here and what is its running time? The solution is desirable in C++\C#. Thanks in advance

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
mamkaololosha, 2014-10-31
@mamkaololosha

the simplest is whip-moriss-pratt

R
Rsa97, 2014-10-31
@Rsa97

If you need to check for a continuous sequence, then this is a search for a substring in the alphabet x, y, z, ...

D
Don Kaban, 2014-11-01
@donkaban

The simplest, "interview-ready" and just right thing to do is to use the standard library.
en.cppreference.com/w/cpp/algorithm/includes
PS Anyway, read en. cppreference.com/w/cpp/algorithm, there is a lot of interesting stuff :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question