跳到正文

个人记录

splay按中序遍历启发式合并复杂度证明

caeious约 5 分钟
原文
文章信息与版本

文章信息

发布
2019年5月17日
收录
2025年12月12日
更新
2026年11月22日
篇幅
约 5 分钟
获赞
5

版本

  1. v1当前

原论文

摘要

Step 1

证明splay是一棵Dynamic Finger Search Tree,访问的复杂度为log d(finger,ai)log\ d(finger,a_i)。

leator and Tarjan introduced splay treessplay\ trees as a class of self-adjusting binary search trees supporting searches, insertions and deletions in amortized O(log n)O(log\ n) time. That splay trees can be used as efficient finger search trees was later proved by Cole[17, 18]: Given an O(n)O(n) initialization cost, the amortized cost of an access at distance d from the preceding access in a splay tree is O(log d)O(log\ d) where accesses include searches, insertions, and deletions. Notice that the statement only applies in the presence of one finger, which always points to the last accessed element.

Step 2

证明合并两棵大小分别为n,m(n≤m)n,m(n \leq m)的Dynamic Finger Search Tree复杂度为O(n log mn)O(n\ log\ \frac{m}{n})。

Optimal merging of two sets also follows as an application of finger search trees [28]. Assume that the two sequences are represented as finger search trees, and that we repeatedly insert the nn elements from the shorter sequence into the larger sequence using a finger that moves monotonically from left to right. If the iith insertion advances the finger did_i positions, we have that the total work of performing the nn finger searches and insertions is O(∑i=1n log di)O(\sum_{i=1}^n\ log\ d_i), where ∑i=1n di≤m\sum_{i=1}^n\ d_i \leq m. By convexity of the logarithm the total work becomes bounded by O(n log mn)O(n\ log\ \frac{m}{n}).

由于将它们合并有(n+mn)n + m \choose n种中序,所以至少需log(n+mn)log{n + m \choose n}次比较,即O(log(n+mn))=O(log(n+mn×n+m−1n−1×⋯×m+11))=O(∑i=1n log(1+mi))≥O(n log mn)O(log{n + m \choose n}) = O(log(\frac{n+ m}{n} \times \frac{n + m - 1}{n - 1} \times \dots \times \frac{m + 1}{1})) = O(\sum_{i=1}^n\ log(1 + \frac{m}{i})) \geq O(n\ log\ \frac{m}{n})为合并它们的下界,所以这是归并两个有序列的最优方法。

Since sets can be represented as sorted sequences, the above merging algorithm gives immediately raise to optimal, i.e. O(log(n+mn))=O(n log mn)O(log{n + m \choose n}) = O(n\ log\ \frac{m}{n}) time, algorithms for set union, intersection, and difference operations [28]. For a survey of data structures for set representations see [41].

Step 3

证明按任意顺序合并nn个点,总复杂度为O(n log n)O(n\ log\ n). 画出merge tree,自底向上归纳可证将根为uu的子树的叶子合并成一棵splay复杂度为log(sizu!)log({siz_u}!), 所以根节点(即所有合并完成时)复杂度为O(log(n!))=O(n log n)O(log(n!)) = O(n\ log\ n).

Q.E.D.