卷別
資料結構及演算法
選擇國立政治大學 2026 · 考試 · 第 2 題
考科資料結構
(5%) A queue is implemented using two stacks, and . The implementation ensures the FIFO property by defining the operations as follows:
- Enqueue: The new element is simply pushed onto .
- Dequeue:
- If is not empty, the top element is popped from .
- If is empty, all elements are first transferred from to (by repeatedly popping from and pushing onto ), and then the top element is popped from .
What is the amortized time complexity of the dequeue operation?
- (A)
- (B)
- (C)
- (D)