liveBook · Manning

Backtracking

As explained in Advanced Algorithms and Data Structures

Backtracking is a technique that reverses or revisits decisions along a path when processing cannot be completed from the current choice.

Backtracking reverses a traversal when the current choice cannot complete the operation, allowing an earlier decision or node to provide the result or continue repair. section 6.2.5 section 10.3.2

A recursive backtracking step typically follows this pattern:

Trie longest prefix

A recursive trie search follows the searched characters. If the path ends without a key, it backtracks; the first key node encountered supplies the longest stored prefix. The operation remains O(m) for a string of length m. section 6.2.5

SS-tree insertion

After inserting into a full leaf, the algorithm splits that leaf and backtracks through its ancestors. Each parent absorbs the replacement children or splits itself, while centroids and radii are recomputed until constraints hold. section 10.3.2

Listing 6.9 Method longestPrefix
function longestPrefix(node, s, prefix)                             #1
  if s == “” then                                                   #2
    if node.keyNode then                                            #3
      return prefix
    else
      return null                                                   #4
  c, tail ← s.splitAt(0)                                            #5
  if node.children[c] == null then                                  #6
    if node.keyNode then return prefix else return null             #7
  else
    result ← longestPrefix (node.children[c], tail, prefix + c)     #8
    if result != null then                                          #9
      return result
    elsif node.keyNode then                                         #10
      return prefix
    else
      return null                                                   #11

Trace the longestPrefix recursion, including its fallback checks while unwinding the path. section 6.2.5

How Advanced Algorithms and Data Structures covers it

How deep it goes
Explains recursive descent, unwinding, fallback checks, ancestor updates, node splits, and stopping conditions.
Examples
Demonstrates longest-prefix lookup and SS-tree insertion after a full leaf requires recursive ancestor splitting.
What it assumes
Assumes recursive tree traversal, trie nodes, child paths, and bounded tree-node capacity.
What you can do after
Implement recursive trie lookup and tree insertion routines that propagate results or structural changes toward the root.
How it connects
Connects backtracking with tries, recursive functions, SS-trees, tree traversal, node splitting, centroids, and bounding envelopes.

Also explained in

Compare how 6 books explain backtracking →

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.