Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
aa:ammortized-analysis [2017/01/11 16:11]
pdmatei created
aa:ammortized-analysis [2019/11/26 13:25] (current)
pdmatei
Line 58: Line 58:
 For the FIFO, we estimate: For the FIFO, we estimate:
   * $math[\hat{c}_{enq} = 3] since each inserted element in $math[l] **may** be subsequently removed from $math[l] and inserted in $math[r]. We charge extra to **amortise** for this potential cost.   * $math[\hat{c}_{enq} = 3] since each inserted element in $math[l] **may** be subsequently removed from $math[l] and inserted in $math[r]. We charge extra to **amortise** for this potential cost.
-  * $mat[\hat{c}_{deq} = 1] which represents the deletion from $math[r].+  * $math[\hat{c}_{deq} = 1] which represents the deletion from $math[r].
  
 To validate this estimation, we verify the **golden rule**. To validate this estimation, we verify the **golden rule**.
Line 122: Line 122:
 where $math[size(l_i)] is the size of the left list after the $math[ith] operation. where $math[size(l_i)] is the size of the left list after the $math[ith] operation.
  
-$math[\hat{c}_{deq} = 1 + 2*size(l_i) - 2*size(l_{i-1}) = 1 + 0 = 1]+For dequeue, we consider two cases: 
 +  * no normalization takes place: ​$math[\hat{c}_{deq} = 1 + 2*size(l_i) - 2*size(l_{i-1}) = 1 + 0 = 1] 
 +  * normalization takes place: $math[\hat{c}_{deq} = 1 + 2*size(l_{i-1}) + 0 - 2*size(l_{i-1}) ​= 1]
  
 note that during dequeueing, the size of the left list does not change. note that during dequeueing, the size of the left list does not change.