# How do you call a subsequence of consecutive elements ?

I wrote a function that returns the position of a given subsequence in a sequence. However, I just realized that I used the term "subsequence" incorrectly: according to Wikipedia, the elements of a subsequence don't need to be consecutive. But my function is actually looking for a "subsequence of consecutive elements"... is there a name for this notion? I thought of substring, but it seems to imply a sequence of characters, and my function is not specific to character strings..

I realize it isn't a very critical issue, but I'd like to give my function an accurate name...

Any idea would be appreciated !

• This site is devoted to research-level theoretical computer science. As such, your question falls out of scope. Hopefully, my answer is nevertheless sufficient. Mar 14, 2011 at 11:41
• ps: subsequence is not an incorrect name, it contains your case, and I think it is not uncommon in some programming languages to use it in the sense you are using it. A possible alternative would be range or interval, but IMHO (contiguous) subsequence is better. Mar 14, 2011 at 12:31
• @Martin, absolutely not... I'm working on arbitrary sequences, there is no arithmetic relation between the elements. And the elements can be of any type, they don't even have to be numbers... Mar 14, 2011 at 14:01
• I believe substrings are by default contiguous, whereas subsequences are not. So "contiguous subsequence" is probably the best name. Mar 14, 2011 at 17:10
• substring works for me ;) Mar 14, 2011 at 18:39

In programming languages and libraries, it is usually called either a substring or a slice.

The former term is ubiquitous, and I would not mind using it even if your "characters" are a bit weird.

The latter term is neutral in the sense that it does not refer to strings. See array slicing in Wikipedia for more information and examples.

As I wrote in the comments, I'd call it a contiguous subsequence.

I suggest the term segment.

In string algorithms, the most established usage is subsequence for the non-contiguous case, and either substring, factor or window for the contiguous case. Incidentally, string and sequence are usually regarded as synonyms (with "sequence" having a bit more biological flavour, but otherwise equivalent). The elements are called characters, but depending on the context, could in fact be integers or anything else, and the same terminology would be used.

The Mathematica system goes against this established usage by having the functions LongestCommonSequence and LongestCommonSubsequence that represent the non-contiguous and the contiguous case respectively. The Mathematica documentation uses the term "scattered" for "non-contiguous".

• Thanks for the detailed answer! I went with substring eventually Mar 19, 2011 at 11:24