← 回題庫

卷別

資料結構

選擇

國立中央大學 2026 · 考試 · 第 9 題

Given a "Perfect Binary Tree" (i.e., every level is full), with a height of hh (total number of nodes n≈2h+1n \approx 2^{h+1}), compare the worst-case space complexity of using a stack for depth-first search (DFS) versus using a queue for breadth-first search (BFS).

  • (A)
    Depth-first search (DFS) is relatively memory-intensive because of its deep recursion depth.
  • (B)
    BFS is relatively memory-intensive because a queue needs to store all the leaf nodes at the lowest level.
  • (C)
    Both consume roughly the same amount of memory O(n)O(n).
  • (D)
    Both consume roughly the same amount of memory O(log⁡n)O(\log n)

標準解析

AI 生成