Substring: Difference between revisions

Content deleted Content added
Superstring: reverse subsentences to answer clarification request; I feel that computing a minimal-length superstring could be NP-hard, but don't have a supporting citation
this has a cite in the body immediately below
 
(16 intermediate revisions by 8 users not shown)
Line 1:
{{Short description|Contiguous part of a sequence of symbols}}
{{About|the definition of a substring|the computer function which performs this operation|String functions (programming)}}{{Distinguish|text=[[Subsequence]], a generalization of substring}}[[File:Substring.png|thumb|"''string''" is a substring of "''substring''"]]
{{Distinguish|text=[[subsequence]], a generalization of substring}}
[[File:Substring.png|thumb|"''string''" is a substring of "''substring''"]]
 
In [[Formal language|formal language theory]] and [[computer science]], a '''substring''' is a contiguous sequence of [[Character (computing)|character]]s within a [[String (computer science)|string]]<!-- Needs a citation. -->.{{Citation needed|date=July 2021}} For instance, "''the best of''" is a substring of "''It was the best of times''". In contrast, "''Itwastimes''" is a subsequence of "''It was the best of times''", but not a substring.
 
'''Prefixes''' and '''suffixes''' are special cases of substrings. A prefix of a string <math>S</math> is a substring of <math>S</math> that occurs at the beginning of <math>S</math>; likewise, a suffix of a string <math>S</math> is a substring that occurs at the end of <math>S</math>.
 
The list of all substrings of the string "''apple''" would be :
"''applea''", "''applap''", "''ppleapp''", "''appappl''", "''pplapple''",
"''plep''", "''appp''", "''ppppl''", "''plpple''",
"''lepl''", "''aple''",
"''pl''", "''lle''",
"''e''", ""
(note the [[empty string]] at the end).
 
== Substring ==
Line 38 ⟶ 47:
== Suffix ==
 
A string <math>s</math> is a suffix<ref name=Lot97/> of a string <math>t</math> if there exists a string <math>p</math> such that <math>t = ps</math>. A ''proper suffix'' of a string is not equal to the string itself. A more restricted interpretation is that it is also not empty.{{ref|Gus97}}. A suffix can be seen as a special case of a substring.
 
Example: The string <code>nana</code> is equal to a suffix (and substring and subsequence) of the string <code>banana</code>:
Line 54 ⟶ 63:
== Superstring ==
 
A '''superstring''' of a finite set <math>P</math> of strings is a single string that contains every string in <math>P</math> as a substring. For example, <math>\text{bcclabccefab}</math> is a superstring of <math>P = \{\text{abcc}, \text{efab}, \text{bccla}\}</math>, and <math>\text{efabccla}</math> is a shorter one. Concatenating all members of <math>P</math>, in arbitrary order, always obtains a trivial superstring of <math>P</math>. Finding superstrings whose length is as small as possible is a more interesting problem.

A string that contains every possible permutation of a specified character set is called a [[superpermutation]].
 
== See also ==
Line 70 ⟶ 81:
| title = Algorithms on Strings, Trees and Sequences: Computer Science and Computational Biology
| publisher = Cambridge University Press
| ___location = USAUS
| isbn = 0-521-58519-8
}}</ref>
Line 92 ⟶ 103:
}}</ref>
}}
 
==External links==
*{{Commonscatinline}}
 
[[Category:String (computer science)]]