卷別
資料結構與演算法
選擇國立臺灣大學 2024 · 考試 · 第 8 題
考科演算法
(5 points) We define the height of a tree to be the maximum number of edges from the root to a leaf. We also define the level of a node , denoted as , to be the height of the subtree rooted at . Which of the following descriptions is correct?
- (A)If is a leaf, then .
- (B)If is an internal node, , where is the set of children of .
- (C)We can compute by starting a breadth-first-search (BFS) from , traversing all nodes of the subtree rooted at , and computing the maximum distance to a leaf as . Since there are no more than 's and each BFS takes time, the total time complexity is .
- (D)We can compute the levels for all nodes by a depth-first-search (DFS) starting from the root of . That is, we can compute the level of an internal node after we compute the values of all children of .
- (E)Since there are tree nodes to visit, the DFS from the root takes time.