卷別
資料結構與演算法
選擇國立臺灣大學 2026 · 考試 · 第 14 題
考科資料結構
(4 points) A queue is implemented using two stacks and as follows. If each or with the stack has a cost of , what is the amortized cost per operation over a sequence of legal queue operations, starting from an empty state with the first operation being ?
ENQUEUE(Q, x):
1 PUSH(Q.S_in, x)
DEQUEUE(Q):
1 if Q.S_out is not empty
2 return POP(Q.S_out)
3 while Q.S_in is not empty
4 PUSH(Q.S_out, POP(Q.S_in))
5 return POP(Q.S_out)
- (A)
- (B)
- (C)
- (D)
- (E)None of the other choices.