3 ms·
Another consideration regarding memory: a binary tree with no parent pointers has two pointers per node. (Traversal then needs temp space due to to recursion or
by kazinator 10y ago
Another consideration regarding memory: a binary tree with no parent pointers has two pointers per node. (Traversal then needs temp space due to to recursion or iteration with explicit stack.)
However, a binary tree can be traversed in O(n) in both directions.
A skip list with a singly-linked level zero cannot be traversed in reverse.
If we make it doubly linked to meet the requirement for reverse traversal then ... it has two pointers per node and then some. There goes your storage advantage.
- sobani 10y agoActually, you can. As per the article, you can view the skiplist as a tree when turned 1/8th. So you can start at the head, put it on the stack, move to the next node referenced at the hightest level, put it on the stack, etc. just like you can start from the top of the tree, put it on the stack, move right, put it on the stack, etc. The advantage of the skiplist over the tree is that you can traverse forward in O(1) space. But both are equally bad in reverse