From the course: Python Data Structures: Trees

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

Traversing a tree - Python Tutorial

From the course: Python Data Structures: Trees

Start my 1-month free trial

Traversing a tree

- [Instructor] And the last section we were given a target node to search for and made a beeline straight to in our tree. Along the way we left a trail a visited nodes as we made each decision about where to go next. But what if instead of the goal being to find a particular target node, the goal was just to systematically visit every node. Now this can be useful for many reasons counting the number of nodes in a tree or finding the maximum and minimum depths for example. Really understanding how to write a program that visits every node of a tree can reveal some pretty cool properties about trees and recursion that might not be obvious at first. So let's take a look at the three types of tree traversal. Technically there are more than just these three types but these are the three types you'll see commonly and that computer scientists commonly use. So there's, pre-order traversal, in-order traversal and post-order traversal.…

Contents