I found a couple of answers online but I don't quite understand why the answer is right:

  1. The length of a string is:
    If a string has no characters, then its length is 0.
    Otherwise, the length of the string is 1 + length of the tail

enter image description here

  • 2
    $\begingroup$ Don't use images as main content of your post. This makes your question impossible to search and inaccessible to the visually impaired; we don't like that. Please transcribe text and mathematics (note that you can use LaTeX) and don't forget to give proper attribution to your sources! $\endgroup$ – dkaeae Apr 29 '19 at 18:47

Strings are concatenations of characters. Hence, any non-empty string $w$ has a first character $x$ and can be written as $w = x w'$, where $w'$ is the tail string. It follows from the definition of a string's length that $|w| = |x w'| = |x| + |w'| = 1 + |w'|$.

| cite | improve this answer | |

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.