nextupprevious
Next:4.7 To Probe FurtherUp:4.6 Amortized Algorithm AnalysisPrevious:4.6.4 Example of Incrementing Binary Integers

4.6.5 Amortized Analysis of Splaying

                                                                     Ci$\displaystyle \sum_{x \in T_i}^{}$ri(x) Result 1

If the ith splaying step is a zig-zig or a zag-zag step at node x, then its amortized complexity ai satisfies 

ai < 3(ri(x) - ri - 1(x))

See Figure 4.26.
 

Figure 4.26: A zig-zig at the ith splaying step
\begin{figure}\par \centerline{\psfig{figure=figures/Fsplaystep.ps,width=5in}}\end{figure}
Since | Ti(x)| = | Ti - 1(z)| as the subtree rooted at z before the splaying step has the same size as that rooted at x after the step.

                                                                                                                            Let

                                                                                                                        $ \alpha$ = | Ti - 1(x)|,$ \beta$ = | Ti(z)|, and $ \gamma$ = | Ti(x)|. Then observe that $ \alpha$$ \beta$$ \leq$$ \gamma$. This is because

Ti - 1(x)  contains components  x, A, B

   
Ti(z)  contains components z, C, D    
Ti(x$\displaystyle \mbox{contains all these components (plus $y$\space besides)}$.      

Thus by (*

ri - 1(x) + ri(z$\displaystyle \leq$ 2ri(x) - 2
$\displaystyle \Rightarrow$  2ri(x) - ri - 1(x) - ri(z) - 2 $\displaystyle \geq$ 0
Adding this to ($ \bullet$), we get 
ai$\displaystyle \leq$ 2ri(x) - 2ri - 1(x) + ri(y) - ri - 1(y)
Before step i, y is the parent of x so that 
| Ti - 1(y)| > | Ti - 1(x)|
After step i, x is the parent of y so that 
| Ti(x)| > | Ti(y)|
Taking logarithms we have 
ri - 1(y) > ri - 1(x) and  ri(x) > ri(y)
Thus we obtain 
ai < 3ri(x) - 3ri - 1(x)
Similarly, we can show Results 2 and 3 below:

Result 2

                            If the ith splaying step is a zig-zag or zag-zig at node x, then its amortized complexity ai satisfies

ai < 2(ri(x) - ri - 1(x))

Result 3

                                                                                                                        If the ith splaying step is a zig or a zag, then

ai < 1 + (ri(x) - ri - 1(x))

Result 4

The total amortized cost over all the splaying steps can be computed by adding the costs of all the splay steps. If there are k such steps, only the last can be a zig or zag and the others are all zig-zag or zig-zag or zag-zig or zag-zag. Since (*) provides the weaker bound, we get,

$\displaystyle \sum_{i=1}^{k}$ai = $\displaystyle \sum_{i=1}^{k-1}$ai + ak
     
  $\displaystyle \leq$ $\displaystyle \sum_{i-1}^{k-1}$ 3(ri(x) - ri - 1(x)) + (1 + 3rk(x) - 3rk - 1(x))
     
  = 1 + 3rk(x) - 3r0(x)
     
  $\displaystyle \leq$ 1 + 3rk(x)
     
  = 1 + 3log n  

Thus the amortized cost of an insertion or retrieval with splaying in a BST with n nodes does not exceed 1 + 3log n upward moves of the target node in the tree.

Result 5

Now consider a long sequence of m splay insertions or retrievals. We seek to compute the actual cost of all these m operations.

Let Tj and Aj be the actual cost and amortized cost of the jthoperation, where j = 1, 2,..., m, now represents a typical insertion or retrieval operation.

We have

$\displaystyle \sum_{j=1}^{m}$Tj$\displaystyle \left(\vphantom{\sum_{j=1}^m \space A_j}\right.$$\displaystyle \sum_{j=1}^{m}$Aj$\displaystyle \left.\vphantom{\sum_{j=1}^m \space A_j}\right)$$\displaystyle \mbox{{$C_O - C_m$}}$
If the tree never has more than n nodes, then C0 and Cm lie between 0 and log n, so that 

                                                                                                        C0 - Cm$\displaystyle \leq$ log n
Also we know that 

                               Aj$\displaystyle \leq$ 1 + 3logn  for j = 1, 2,..., m
Thus the above becomes 
                            $\displaystyle \sum_{j=1}^{m}$Tj = m(1 + 3logn) + log n
The above gives the total actual time of m insertions or retrievals on a tree that never has more than n nodes.

This gives O(log n) actual running time for each operation.


nextupprevious
Next:4.7 To Probe FurtherUp:4.6 Amortized Algorithm AnalysisPrevious:4.6.4 Example of Incrementing Binary Integers
eEL,CSA_Dept,IISc,Bangalore