Skip to content

Commit 832a2ac

Browse files
Update datastructures/trees/binary/search_tree/binary_search_tree.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent a22aa85 commit 832a2ac

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

datastructures/trees/binary/search_tree/binary_search_tree.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ def breadth_first_search(self) -> List[Any]:
406406
Performs a breadth first search through a Binary Tree
407407
This will traverse the tree level by level and depth by depth. Using a Queue to put elements into the queue
408408
"""
409+
result = []
409410
queue = FifoQueue()
410411

411412
# start off by adding the root node
@@ -414,13 +415,16 @@ def breadth_first_search(self) -> List[Any]:
414415
# while the queue is not empty, we want to traverse the tree and add elements to the queue,
415416
while not queue.is_empty():
416417
current_node = queue.dequeue()
418+
result.append(current_node.data)
417419

418420
if current_node.left:
419421
queue.enqueue(current_node.left)
420422

421423
if current_node.right:
422424
queue.enqueue(current_node.right)
423425

426+
return result
427+
424428
def pre_order(self) -> List[Any]:
425429
"""
426430
Type of Depth First Traversal (DFS) for binary trees which will start at root node and proceed to the left

0 commit comments

Comments
 (0)