資料結構›Ch5 樹狀結構
第 21 題/共 48 題
◀ DS 21/48
21. Binary Search Tree、Pseudo-code、Lowest Common Ancestor
#DS-05-021中Binary Search TreePseudo-codeLowest Common Ancestor
  1. (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 TT. 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 樹狀結構
本章題號 · 21–40 / 48