Step 1: Start at root 20 with horizontal distance (hd) = 0
hd=0: 20
Queue: [(20,0)]
Why: We begin from the root at horizontal distance zero.
Step 2: Process node 20, update map hd=0 -> 20, enqueue left child 8 (hd=-1), right child 22 (hd=1)
Map: {-1: -, 0: 20, 1: -}
Queue: [(8,-1), (22,1)]Why: Store node 20 for hd=0, add children with updated hd.
Step 3: Process node 8, update map hd=-1 -> 8, enqueue left child 5 (hd=-2), right child 3 (hd=0)
Map: {-2: -, -1: 8, 0: 20, 1: -}
Queue: [(22,1), (5,-2), (3,0)]Why: Node 8 is lower at hd=-1, add its children.
Step 4: Process node 22, update map hd=1 -> 22, enqueue right child 25 (hd=2)
Map: {-2: -, -1: 8, 0: 20, 1: 22, 2: -}
Queue: [(5,-2), (3,0), (25,2)]Why: Node 22 is lowest so far at hd=1, add child 25.
Step 5: Process node 5, update map hd=-2 -> 5, no children to enqueue
Map: {-2: 5, -1: 8, 0: 20, 1: 22, 2: -}
Queue: [(3,0), (25,2)]Why: Node 5 is lowest at hd=-2.
Step 6: Process node 3, update map hd=0 -> 3, enqueue left child 10 (hd=-1), right child 14 (hd=1)
Map: {-2: 5, -1: 8, 0: 3, 1: 22, 2: -}
Queue: [(25,2), (10,-1), (14,1)]Why: Node 3 is lower than 20 at hd=0, add children.
Step 7: Process node 25, update map hd=2 -> 25, no children
Map: {-2: 5, -1: 8, 0: 3, 1: 22, 2: 25}
Queue: [(10,-1), (14,1)]Why: Node 25 is lowest at hd=2.
Step 8: Process node 10, update map hd=-1 -> 10, no children
Map: {-2: 5, -1: 10, 0: 3, 1: 22, 2: 25}
Queue: [(14,1)]Why: Node 10 is lower than 8 at hd=-1.
Step 9: Process node 14, update map hd=1 -> 14, no children
Map: {-2: 5, -1: 10, 0: 3, 1: 14, 2: 25}
Queue: []Why: Node 14 is lower than 22 at hd=1.
Result: Bottom view nodes from left to right:
5 -> 10 -> 3 -> 14 -> 25 -> null