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 all nodes at a particular depth

Getting all nodes at a particular depth - Python Tutorial

From the course: Python Data Structures: Trees

Start my 1-month free trial

Getting all nodes at a particular depth

- [Instructor] We're going to write a function that takes in an arbitrary depth, like two, and prints out the nodes at that depth from left to right. So while getting all the nodes at a particular depth might not seem immediately useful, it's essential for some of the more advanced tasks when working with trees, especially printing them which is a challenge in the next video. So imagine if you will, a tiny, little person attached to the root by a bungee cord. There we go. And they leap off the root of the tree, and then get yanked back up when the cord runs out. And then they go back down and then up again, then down, then up again, then down. And each time at the point of maximum descent, they record the node that they're currently at before being yanked back up again. And they do this until they recorded every node in a straight line across the tree. Now, this might seem like a bizarre visualization, tiny, little…

Contents