資料結構›Ch5 樹狀結構第 21 題/共 48 題
21. Binary Search Tree、Pseudo-code、Lowest Common Ancestor
#DS-05-021中Binary Search TreePseudo-codeLowest Common Ancestor
- (b) 6%
a = n1
b = n2
while a != b:
a = a.p if a else n2
b = b.p if b else n1
return a
In the above pseudo code, n1 and n2 are two nodes in a binary search tree . a = a.p if a else n2 means if a is not NULL then set a to a.p otherwise set a to n2. What does this piece of code compute (what is "a" returned by the function)?
📄 交大115
▤完整推導請見《WH 資工筆記 · 資料結構》Ch5 樹狀結構