Led by: Haseeb Qureshi, instructor at App Academy
######Topics:
- What are strings?
- Think about them as special cases of arrays!
- How do they work in C? -- Null terminated, linear length lookup
- P-Strings (Pascal) and RStrings (Ruby)
- Mutability vs immutability
- String concatenation
- String Buffers for faster concatenation (Ruby's String#join)
- ASCII characters vs UTF-8 (Variable-length encoding)
- Series of bytes vs series of characters
- Copy-on-write optimization
-
Reverse a string (don't use
String#reverse
orArray#reverse
). Do it by hand.def reverse(str)
-
Find the first non-repeating character in a String. (Try to do this in
O(n)
time.)def first_nonrepeating_char(str)
-
Given two strings, determine if the strings are anagrams. E.g., "bat" is an anagram of "tab," but not of "bate" or "at"
def anagrams?(str1, str2)
-
Determine if a string is a rotation of another string. (Don't use the
Array#rotate
method.) Ex:deabc
is a rotation ofabcde
(wrapping around by 2 to the right).def rotation?(str1, str2)
-
Find all of the permutations of a string. E.g., the permutations of "abc" are: "abc", "acb", "bac", "bca", "cab", "cba".
def permutations(str)
-
If you reversed a string iteratively, do it recursively. If you did it recursively, do it iteratively.
def reverse2(str)
-
Determine if, given three strings, the first two strings can be interleaved to produce the third string. An interleaving is when the characters of two strings are combined in some order to produce a third string, but with the ordering of characters maintained.
E.g., "abc" and "def" can be interleaved to make "adbecf". However, if you took away any letter, or changed the order to "acdfeb", it would no longer be a valid interleaving.
`def is_interleaved?(str1, str2, maybe_interleaved_string)`
Read about and implement the Boyer-Moore-Horspool text search algorithm.
Boyer-Moore-Horspool is the most common general-use string search algorithm, and it’s extremely fast for most practical text search requirements.
Python, Java, Go, JavaScript (V8) and many other string search implementations use the Boyer-Moore-Horspool for text searching. Ruby actually used to use the Rabin-Karp algorithm, and it now uses a home-spun algorithm which is an adaptation of Knuth-Morris-Pratt. But generally speaking, Boyer-Moore-Horspool is the gold standard for general-purpose text search.