From the course: Python: Recursion

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Traversing a tree using recursion: Overview

Traversing a tree using recursion: Overview - Python Tutorial

From the course: Python: Recursion

Start my 1-month free trial

Traversing a tree using recursion: Overview

- [Instructor] We are now going to discuss one of the most important applications of recursion, that is traversing tree structures. So a tree is a nonlinear data structure consisting of nodes connected by directed edges as you can see in this diagram here. A tree consists of a root node and one or more subtrees. So this is where the recursive definition comes in. So a subtree is itself a tree. So for example, in our diagram here, node A is the root. Node A is also the parent of B, C, and D. Node E and F are the child nodes of D. And G is the child node of B. So a set of nodes and edges comprised of a parent node and all its descendants is called a subtree. For example, the nodes D, E, and F form a subtree. Nodes with no child nodes are called leaf nodes. In this tree, nodes C, E, F, and G are leaf nodes. And a subtree may consist of a leaf node alone. So some definitions. The root is the top most node of the tree.…

Contents