Is empty string can be a prefix or suffix of a string?

1.2k views Asked by At

So lately I was solving a problem called unique prefix tree (or Trie) and there I was confused about the term prefix so I dig into it as far as possible. And what I found by definition is like,

"A string x is a prefix of another string y if there is a string v such that y = xv. v is called a suffix of y."

So from this definition, I have a question arises in my mind which is, can a string be a prefix of itself? I think, it is. A string can be a prefix of itself.

But according to the definition, if a string is prefix of itself then v should be a empty string. And, v is also a suffix of y. So again question arises is like, then can empty string be a suffix of a string!!

1

There are 1 answers

1
Aviv Profesorsky On

Wikipedia put it nicely - All the descendants of a node have a common prefix of the string associated with that node, and the root is associated with the empty string.

For example, nodes associated with the string "tea", "ted" and "ten" have a common prefix of "te", preceded by prefix of "t" which root is the empty string.

An empty string is, according to the theory, still a string but with a length of zero, but it is not much of a suffix more than a root, it's as if you would say that 4 is 0 + 2 + 2, you could say that but you would you?