Skip to content

Commit d3b8bbd

Browse files
djeadaCopilot
andauthored
Update notes/brain_teasers.md
Co-authored-by: Copilot <[email protected]>
1 parent a48d253 commit d3b8bbd

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

notes/brain_teasers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ Arrays are basic data structures that store elements in a continuous block of me
4848
Strings, as sequences of characters, often require special handling due to their immutable nature in some languages and the variety of operations performed on them.
4949

5050
* In languages with *immutable strings*, concatenating inside a loop with `+` can be very slow—$O(n^2)$ time. Instead, use tools like `StringBuilder` in Java or `''.join(list_of_strings)` in Python to bring it down to $O(n)$.
51-
* For *string searching*, algorithms like KnuthMorrisPratt (KMP), RabinKarp, or BoyerMoore are much faster than the naive $O(nm)$ approach.
51+
* For *string searching*, algorithms like Knuth-Morris-Pratt (KMP), Rabin-Karp, or Boyer-Moore are much faster than the naive $O(nm)$ approach.
5252
* *Tries (prefix trees)* let you store and retrieve strings with shared prefixes efficiently. They’re common in autocomplete, spell-checkers, and IP routing.
5353
* *Regular expressions* are powerful for pattern matching, but they need careful design—badly written patterns can cause exponential slowdowns.
5454
* Always keep *Unicode and character encoding* (UTF-8, ASCII, etc.) in mind when handling strings, especially with international text or external data. It prevents bugs and ensures proper compatibility.
5555
* For *anagram checks*, compare character counts with arrays or hash maps. For *palindrome checks*, the two-pointer method or comparing against the reversed string gives a simple, efficient solution.
5656
* *Substring and slicing operations* can vary in cost depending on the language. In some (like Python), slices create new strings, while in others (like Java, newer versions), substrings copy data. Always be mindful of hidden overhead.
5757
* When dealing with *very large text processing*, consider using *streaming* or *buffered reading* instead of loading everything into memory at once.
58-
* *Hashing strings* (e.g., rolling hash) is useful for fast lookups, substring checks, or detecting duplicates, especially in algorithms like RabinKarp or for building hash-based data structures.
58+
* *Hashing strings* (e.g., rolling hash) is useful for fast lookups, substring checks, or detecting duplicates, especially in algorithms like Rabin-Karp or for building hash-based data structures.
5959
* *Suffix arrays* and *suffix trees* are powerful for advanced text processing tasks like pattern matching, longest common substring, and text compression.
6060
* *String interning* (pooling identical strings) can save memory and speed up equality checks in languages like Java, but overuse can increase GC pressure.
6161
* For *case-insensitive comparisons*, normalize strings first (e.g., `.lower()` in Python, `.toLowerCase()` in Java), but remember locale-specific rules (e.g., Turkish dotted/dotless "i").

0 commit comments

Comments
 (0)