Glossary
Checking for a Substring
An algorithm that determines if a smaller string (the target substring) exists as a contiguous sequence of characters within a larger string.
Example:
The checking for a substring algorithm would confirm that "cat" is present in "The cat sat on the mat.".
String reversal
An algorithm that constructs a new string by arranging the characters of an original string in the opposite order.
Example:
Applying string reversal to "computer" would yield "retupmoc".
equals(String other)
A String method that compares two strings to determine if they contain the exact same sequence of characters, returning `true` if they do and `false` otherwise.
Example:
To check if String user_input matches "password", you would use user_input.*equals*("password").
for loops
A control flow statement that allows a block of code to be executed repeatedly, typically for a fixed number of iterations or while a condition is true.
Example:
To process each character in a string, you would use a for loop like for (int i = 0; i < s.length(); i++).
indices
Integer values that represent the position of a character within a string, starting from 0 for the first character.
Example:
In the string "Apple", the character 'P' is at index 1, and 'e' is at index 4.
length()
A String method that returns the number of characters in the string.
Example:
For String fruit = "banana";, fruit.*length*() would return 6.
sliding window
An algorithmic technique that processes a contiguous subsegment of data (the 'window') by moving it incrementally across a larger data structure.
Example:
To find all substrings of length 3 in "abcdef", a sliding window of size 3 would move from "abc" to "bcd", then "cde", and finally "def".
substring() method
A String class method used to extract a portion of a string, creating and returning a new string.
Example:
If String word = "keyboard";, using the substring() method like word.substring(3, 6) would return "boa".
substring(int beginIndex, int endIndex)
A String method that returns a new string from the original, starting at `beginIndex` (inclusive) and ending at `endIndex` (exclusive).
Example:
Given String phrase = "Hello World";, phrase.*substring*(6, 11) would extract "World".
tracing
The process of manually stepping through an algorithm's execution with specific input values to understand its behavior and verify correctness.
Example:
When debugging a string reversal algorithm, tracing the result variable's value at each loop iteration helps visualize the string being built.