2
$\begingroup$

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 !

$\endgroup$
  • 2
    $\begingroup$ This site is devoted to research-level theoretical computer science. As such, your question falls out of scope. Hopefully, my answer is nevertheless sufficient. $\endgroup$ – Dave Clarke Mar 14 '11 at 11:41
  • 1
    $\begingroup$ 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. $\endgroup$ – Kaveh Mar 14 '11 at 12:31
  • 2
    $\begingroup$ @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... $\endgroup$ – Thomas Levesque Mar 14 '11 at 14:01
  • 2
    $\begingroup$ I believe substrings are by default contiguous, whereas subsequences are not. So "contiguous subsequence" is probably the best name. $\endgroup$ – Peter Shor Mar 14 '11 at 17:10
  • 5
    $\begingroup$ substring works for me ;) $\endgroup$ – Suresh Venkat Mar 14 '11 at 18:39
9
$\begingroup$

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.

| cite | improve this answer | |
$\endgroup$
7
$\begingroup$

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

| cite | improve this answer | |
$\endgroup$
6
$\begingroup$

I suggest the term segment.

| cite | improve this answer | |
$\endgroup$
3
$\begingroup$

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".

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks for the detailed answer! I went with substring eventually $\endgroup$ – Thomas Levesque Mar 19 '11 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.