Introduction
This Python challenge is about implementing breadth-first traversal on a binary tree.
This tutorial is from open-source community. Access the source code
This Python challenge is about implementing breadth-first traversal on a binary tree.
Given a binary tree, implement a function that performs a breadth-first traversal on the tree. The function should call an input method visit_func
on each node when it is processed.
To solve this problem, the following requirements must be met:
visit_func
method should be called on each node when it is processed.Suppose we have a binary tree with the following structure:
5
/ \
2 8
/ \
1 3
Performing a breadth-first traversal on this tree would result in the following sequence of nodes being visited: 5, 2, 8, 1, 3
.
In this Python challenge, we implemented breadth-first traversal on a binary tree. The solution required a Node class with an insert method, and the visit_func
method was called on each node when it was processed. The solution was able to fit in memory and produced the correct sequence of nodes when performing a breadth-first traversal on a binary tree.