From the course: Python Data Structures: Trees

Unlock the full course today

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

Getting the maximum height of a tree

Getting the maximum height of a tree - Python Tutorial

From the course: Python Data Structures: Trees

Start my 1-month free trial

Getting the maximum height of a tree

- [Instructor] When computer scientists talk about the height of a tree, they mean how many nodes that are from the root to the leaf at the deepest part of the tree. The height of a tree is it's maximum height. So, this tree with a very shallow and a very deep part still has a height of four. One, two, three four. Remember, the height is important because it determines the maximum run time for the search of a tree. So if I'm trying to find this node, the two, it takes me four steps. Even though there might not be that much stuff in the tree. So let's look at how to find the maximum height, or the height of the tree. The basic idea is for each node, starting with the root tree recursively call get height for each of its children. And those children call get height for their children, et cetera. Each time get height as recursively called, the starting height that node is given and incremented. So here, the starting…

Contents