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: Process node 20 at hd=0, update map hd=0 -> 20
Queue: [(8, hd=-1), (22, hd=1)]
Bottom view map: {0: 20}Why: First node at hd=0 is 20, so map records it
Step 3: Process node 8 at hd=-1, update map hd=-1 -> 8
Queue: [(22, hd=1), (5, hd=-2), (3, hd=0)]
Bottom view map: {-1: 8, 0: 20}Why: Node 8 is lowest so far at hd=-1; update map
Step 4: Process node 22 at hd=1, update map hd=1 -> 22
Queue: [(5, hd=-2), (3, hd=0), (25, hd=2)]
Bottom view map: {-1: 8, 0: 20, 1: 22}Why: Node 22 is lowest so far at hd=1; update map
Step 5: Process node 5 at hd=-2, update map hd=-2 -> 5
Queue: [(3, hd=0), (25, hd=2)]
Bottom view map: {-2: 5, -1: 8, 0: 20, 1: 22}Why: Node 5 is lowest so far at hd=-2; update map
Step 6: Process node 3 at hd=0, update map hd=0 -> 3 (overwrites 20)
Queue: [(25, hd=2), (10, hd=-1), (14, hd=1)]
Bottom view map: {-2: 5, -1: 8, 0: 3, 1: 22}Why: Node 3 is lower than 20 at hd=0, so update map
Step 7: Process node 25 at hd=2, update map hd=2 -> 25
Queue: [(10, hd=-1), (14, hd=1)]
Bottom view map: {-2: 5, -1: 8, 0: 3, 1: 22, 2: 25}Why: Node 25 is lowest so far at hd=2; update map
Step 8: Process node 10 at hd=-1, update map hd=-1 -> 10 (overwrites 8)
Queue: [(14, hd=1)]
Bottom view map: {-2: 5, -1: 10, 0: 3, 1: 22, 2: 25}Why: Node 10 is lower than 8 at hd=-1, update map
Step 9: Process node 14 at hd=1, update map hd=1 -> 14 (overwrites 22)
Queue: []
Bottom view map: {-2: 5, -1: 10, 0: 3, 1: 14, 2: 25}Why: Node 14 is lower than 22 at hd=1, update map
Result: Bottom view nodes by horizontal distance:
-2: 5 -> -1: 10 -> 0: 3 -> 1: 14 -> 2: 25
Answer: 5 10 3 14 25