摊还分析与一道例题
worst−case  bound≥amortized  bound≥average−case  bound worst-case \,\,bound \ge amortized\,\,bound\ge average-case\,\,bound worst−casebound≥amortizedbound≥average−casebound
分析方法
- aggregate analysis 聚合分析
- accounting mothod 核算法
- potential method 势能函数法
题目:(来自浙江大学PTA,作者叶德社老师)
A queue can be implemented by using two stacks SAS_ASA and SBS_BSB as follows:
-
- To enqueue x, we push x onto SAS_ASA .
-
- To dequeue from the queue, we pop and return the top item from SBS_BSB . However, if SBS_BSB is empty, we first fill it (and empty SAS_ASA ) by popping the top item from