

Skip lists in Python - helwr
http://infohost.nmt.edu/tcc/help/lang/python/examples/pyskip/

======
sonoffett
The relevant paper, "Skip Lists: A Probabilistic Alternative to Balanced
Trees":
[http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.117...](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.117.6383&rep=rep1&type=pdf)

------
joe_the_user
Serious question: Is it worth implementing this kind of data structure in
Python. Wouldn't Python's overhead overwhelm any speediness you'd get?

~~~
ColinWright
The speediness you get is algorithmic. SkipLists can give you log time
operations on a list - Python can largely only give you linear time.

(The above is a serious simplification, but contains enough truth to be worth
stating. No doubt others more knowledgeable than I can expand and enhance.)

~~~
jerf
"SkipLists can give you log time operations on a list"

So can balanced binary trees, and a number of other structures. I'd demand
benchmarks, because Python is not C (and I don't mean just trivially, I mean,
it is _very_ not just C); just as one for instance, are you hitting a pessimal
case with the GC with this algorithm? You never know.

I'm not actually demanding them, since it didn't seem the point of this
exercise. My point is that you can't just assume.

~~~
liuliu
Besides, if I remember correctly, the most convincing point of skip list is
that it provides better concurrency. In the environment where python still
have GIL, I would be skeptical about that.

~~~
pjscott
Exactly. Skip lists are great for two reasons (and as far as I know, _only_
these two reasons):

1\. They're really cool and clever. This is a valid reason.

2\. They offer easier concurrency than most alternatives. It's straightforward
(though not quite easy, unless you have transactional memory) to make a lock-
free concurrent skip list. Try that with a heap or a red-black tree, and
you'll quickly run into all sorts of memory conflicts and crazy-complicated
locking. The fact that a skip list only provides probabilistic logarithmic
time bounds really makes coordination between threads easier.

(Note that it's possible to do some similar stuff with modified versions of
other data structures. For example, you can make a good concurrent dictionary
by taking a red-black tree, relaxing the invariants, and adding a periodic
rebalancing thread to run in the background. But that's a topic too long to
fit into this post.)

~~~
VBprogrammer
I think the biggest advantage of skip lists is that if a man held a gun to my
head and forced me to implement a logarithmic time algorithm I could implement
skip lists in an hour or so from memory. Any of the others...maybe given a
week and a couple of good books.

~~~
ColinWright

      ... if a man held a gun to my head and forced me
      to implement a logarithmic time algorithm I could
      implement skip lists in an hour or so ...
    

Does this happen to you often?

