> Nick Parlante 8/2026
Think about the string 'Kitten' in the computer...
The simplest algorithms work on the characters themselves, e.g. is there an 'e' in the string? (Answer: Yes). How many 't' characters are there in this string? (Answer: 2).
At another level, the characters in the string are each identified by an index number — the 'K' is at 0, the 'i' is at 1, and so on (computer systems number things starting with 0). Some algorithms work with the index numbers, e.g. what is the index number of the second 't'? (Answer: 3)
Adding or subtracting with an index number enables a sort spatial reference within the string, e.g. what is the 3rd character after the 'i'? The 'i' is at index 1. Adding 3, so 1 + 3 = 4, gives the index 4, which is the 'e'.
What is the 3rd character after the 'e'? The 'e' is at 4. Adding 3 yields the index 7. However the last index in 'Kitten' is 5, so 7 is too big, it is past the end of the string. There is no 3rd character after the 'e'. For this little algorithm, the operations and tests are in the domain of the index numbers, not the characters.
When you are trying to decipher an algorithm, keep the two levels in mind — sometimes the algorithm is about the data itself, and sometimes it's in the domain of the indexes.
Background - teaching introductory computer science, I see countless examples which demonstrate the data vs. index split. On its face, it's a fairly obvious feature. Ultimately, I decided that putting it in words might help beginners get their ideas organized, and it gives me something to link to when we start string algorithms.
>: Nick's Home
Nick Parlante nick.parlante -at- cs.stanford.edu