Step 1: Start BFS from root (20) at horizontal distance 0
Queue: [(20, hd=0)]
Bottom view map: {}Why: We begin from root to explore all nodes level by level with their horizontal distances
Step 2: Pop (20,0), update bottom view at hd=0 with 20
Queue: []
Bottom view map: {0: 20}Why: First node at hd=0 is 20, so bottom view at 0 is 20
Step 3: Add left child (8, hd=-1) and right child (22, hd=1) to queue
Queue: [(8,-1), (22,1)]
Bottom view map: {0: 20}Why: Children are added with updated horizontal distances
Step 4: Pop (8,-1), update bottom view at hd=-1 with 8
Queue: [(22,1)]
Bottom view map: {0: 20, -1: 8}Why: First node at hd=-1 is 8
Step 5: Add left child (5,-2) and right child (3,0) of 8 to queue
Queue: [(22,1), (5,-2), (3,0)]
Bottom view map: {0: 20, -1: 8}Why: Add children with their horizontal distances
Step 6: Pop (22,1), update bottom view at hd=1 with 22
Queue: [(5,-2), (3,0)]
Bottom view map: {0: 20, -1: 8, 1: 22}Why: First node at hd=1 is 22
Step 7: Add right child (25,2) of 22 to queue
Queue: [(5,-2), (3,0), (25,2)]
Bottom view map: {0: 20, -1: 8, 1: 22}Step 8: Pop (5,-2), update bottom view at hd=-2 with 5
Queue: [(3,0), (25,2)]
Bottom view map: {0: 20, -1: 8, 1: 22, -2: 5}Why: First node at hd=-2 is 5
Step 9: Pop (3,0), update bottom view at hd=0 with 3 (overwrite 20)
Queue: [(25,2)]
Bottom view map: {0: 3, -1: 8, 1: 22, -2: 5}Why: 3 is lower than 20 at hd=0, so update bottom view
Step 10: Add left child (10,-1) and right child (14,1) of 3 to queue
Queue: [(25,2), (10,-1), (14,1)]
Bottom view map: {0: 3, -1: 8, 1: 22, -2: 5}Why: Add children with their horizontal distances
Step 11: Pop (25,2), update bottom view at hd=2 with 25
Queue: [(10,-1), (14,1)]
Bottom view map: {0: 3, -1: 8, 1: 22, -2: 5, 2: 25}Why: First node at hd=2 is 25
Step 12: Pop (10,-1), update bottom view at hd=-1 with 10 (overwrite 8)
Queue: [(14,1)]
Bottom view map: {0: 3, -1: 10, 1: 22, -2: 5, 2: 25}Why: 10 is lower than 8 at hd=-1, update bottom view
Step 13: Pop (14,1), update bottom view at hd=1 with 14 (overwrite 22)
Queue: []
Bottom view map: {0: 3, -1: 10, 1: 14, -2: 5, 2: 25}Why: 14 is lower than 22 at hd=1, update bottom view
Result: -2: 5 -> -1: 10 -> 0: 3 -> 1: 14 -> 2: 25
Bottom view nodes: 5 10 3 14 25