Skip to main content
100%

Recursive depth-first search

✓ Published0🌍 Public
Aantonyross
Last edited Mar 21, 2016
Created on Mar 21, 2016

This example demonstrates a recursive depth-first search through a tree of Node objects, where each node holds a value and a list of children. The search traverses the tree from the root downward, checking each node’s value and recursively exploring children until a match is found, returning the target node or None. The code builds a sample tree with letters (a through h) and prints the result of searching for 'g', using plain Python classes and methods like `get_value()` and `get_children()`. No external visualization libraries are used; the output is text-based, showing the found node.

AI-generated description

Similar vizzes