Step 1: Start at root 20 with horizontal distance (hd) = 0
hd=0: 20
Queue: [(20,0)]
Why: We begin BFS from root at hd 0 to track vertical lines
Step 2: Visit 20, update bottom view at hd=0 to 20, enqueue left child 8 (hd=-1), right child 22 (hd=1)
Bottom view: {-1: -, 0: 20, 1: -}
Queue: [(8,-1), (22,1)]Why: 20 is the first node at hd 0, so bottom view at 0 is 20
Step 3: Visit 8, update bottom view at hd=-1 to 8, enqueue left child 5 (hd=-2), right child 3 (hd=0)
Bottom view: {-2: -, -1: 8, 0: 20, 1: -}
Queue: [(22,1), (5,-2), (3,0)]Why: 8 is lowest at hd -1 so far; 3 at hd 0 may replace 20 later
Step 4: Visit 22, update bottom view at hd=1 to 22, enqueue right child 25 (hd=2)
Bottom view: {-2: -, -1: 8, 0: 20, 1: 22, 2: -}
Queue: [(5,-2), (3,0), (25,2)]Why: 22 is lowest at hd 1 so far
Step 5: Visit 5, update bottom view at hd=-2 to 5, no children
Bottom view: {-2: 5, -1: 8, 0: 20, 1: 22, 2: -}
Queue: [(3,0), (25,2)]Why: 5 is lowest at hd -2
Step 6: Visit 3, update bottom view at hd=0 to 3, enqueue left child 10 (hd=-1), right child 14 (hd=1)
Bottom view: {-2: 5, -1: 8, 0: 3, 1: 22, 2: -}
Queue: [(25,2), (10,-1), (14,1)]Why: 3 is lower than 20 at hd 0, so replace 20
Step 7: Visit 25, update bottom view at hd=2 to 25, no children
Bottom view: {-2: 5, -1: 8, 0: 3, 1: 22, 2: 25}
Queue: [(10,-1), (14,1)]Why: 25 is lowest at hd 2
Step 8: Visit 10, update bottom view at hd=-1 to 10, no children
Bottom view: {-2: 5, -1: 10, 0: 3, 1: 22, 2: 25}
Queue: [(14,1)]Why: 10 is lower than 8 at hd -1, so replace 8
Step 9: Visit 14, update bottom view at hd=1 to 14, no children
Bottom view: {-2: 5, -1: 10, 0: 3, 1: 14, 2: 25}
Queue: []Why: 14 is lower than 22 at hd 1, so replace 22
Result: Bottom view nodes from left to right:
5 -> 10 -> 3 -> 14 -> 25 -> null