...

/

SkiplistSSet: An Efficient SSet

SkiplistSSet: An Efficient SSet

Learn to implement a SkiplistSSet.

A SkiplistSSet uses a skiplist structure to implement the SSet interface. When used in this way, the list L0L_0 stores the elements of the SSet in sorted order.

The find() method

The find(x) method works by following the search path for the smallest value yy such that yxy \ge x:

Press + to interact
Node < T > findPredNode(T x) {
Node < T > u = sentinel;
int r = h;
while (r >= 0) {
while (u.next[r] != null && compare(u.next[r].x, x) < 0)
u = u.next[r]; // go right in list r
r--; // go down into list r-1
}
return u;
}
T find(T x) {
Node < T > u = findPredNode(x);
return u.next[0] == null ? null : u.next[0].x;
}

Following the search path for yy is easy: when situated at some node, u, in LrL_r ...

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy