liveBook · Manning

Substring

As explained in Advanced Algorithms and Data Structures

A substring is a contiguous sequence of characters contained within a string.

A substring is handled as the portion of a search string still being matched. Trie search repeatedly separates that string into its first character and remaining tail, then follows the corresponding edge. section 6.2.2

Use substring matching in trie and radix-trie traversal as follows:

  • If the remaining substring is empty, inspect the current node to determine whether the complete key is stored there. section 6.2.2
  • Otherwise, compare its first character with outgoing edges and continue with the tail when a matching edge exists. section 6.2.2
  • In a radix trie, compare the remaining substring with an edge label, which may match several characters or only a common prefix. section 6.3.1

Failed search

A search can fail when the next character has no outgoing edge, or when the substring is exhausted at an intermediate node that is not marked as storing a key. section 6.2.2

Figure 6.15 Possible cases comparing a search string to a node's links. (1) An edge’s label completely matches part of the string. (2) An edge’s label and the search string have a common prefix that is shorter than both strings. (3) The search string is a prefix of one of the edge’s labels. (4) The search string has no common prefix with any of the edges.

Compare the four radix-trie cases: complete edge-label matching, a shorter common prefix, the search string as an edge-label prefix, and no common prefix. section 6.3.1

How Advanced Algorithms and Data Structures covers it

How deep it goes
Explains recursive decomposition, terminal checks, failed paths, and radix common-prefix cases, but does not develop general substring algorithms.
Examples
Uses recursive first-character splitting, missing-edge failure, intermediate-node failure, and four radix edge-matching cases.
What it assumes
Assumes strings, character access, trie nodes, outgoing edges, and either recursive calls or explicit loops.
What you can do after
Apply it via trie or radix-trie search to follow complete keys and diagnose prefix or edge-matching failures.
How it connects
Connects substrings with trie, radix tree, prefix matching, recursion, and binary search.

Also explained in

Compare how 5 books explain substring →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Advanced Algorithms and Data Structures. The section links point to the parts of the book it draws on.