3. What is the output of the following code snippet that calculates the maximum width of a binary tree?
class Node:
def __init__(self, val):
self.val = val
self.left = None
self.right = None
def widthOfBinaryTree(root):
if not root:
return 0
max_width = 0
queue = [(root, 0)]
while queue:
level_length = len(queue)
_, first_index = queue[0]
for i in range(level_length):
node, index = queue.pop(0)
if node.left:
queue.append((node.left, 2 * index))
if node.right:
queue.append((node.right, 2 * index + 1))
max_width = max(max_width, index - first_index + 1)
return max_width
root = Node(1)
root.left = Node(2)
root.right = Node(3)
root.left.left = Node(4)
root.right.right = Node(5)
print(widthOfBinaryTree(root))