What is the output of this Python code that performs a Level Order Traversal (BFS) on a Binary Tree?
from collections import deque
class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def level_order(root):
if root is None:
return
nodes = deque([root])
while(len(nodes) > 0):
curr = nodes.popleft()
print(curr.data, end=' ')
if curr.left:
nodes.append(curr.left)
if curr.right:
nodes.append(curr.right)
# Binary Tree Construction
root = Node(1)
root.left = Node(2)
root.right = Node(3)
root.left.left = Node(4)
root.left.right = Node(5)
level_order(root)