skiplist 几句话介绍

skiplist有以下两个核心feature:

1. 本质上由若干个linked list组成(每个linked list被称为一层)

2. 上一层元素是下一层元素的索引,比如第一层元素包括{1,2,3,4,5,6,7,8,9,10},则第二层元素可以包含{1, 4, 8, 10}这就相当于对第一层做了索引,查找速度变快了。最底层的linked list必须包含所有元素,顶层的linked list则可以只包含头尾节点。

形式化的说:

find(x):

while (true)

{

    while (p->next->key < x) p = p->next;

    if (p->down == NULL) return p->next;

    p = p->down;

}

insert(x) :

find(x)

insert new element x into lowest level k linked list. This is because the above feature 2, if level k linked list include element x, then all lower level linked list contain element x too.

but how to decide k ? we can make a ramdom selection, e.g. k start from 0, and we throw coin, if front side of that coin face up, k++, else return k

delete(x)

find (x)

delete x from each level linked list

the expect average complxity of above three operations is log(n)

posted on 2011-09-15 20:33  RaymondSQ  阅读(319)  评论(0编辑  收藏  举报