CSSE 230
SkipList Programming Assignment
Overview
The purpose of this
exercise is to understand in detail the mechanics of insertion and removal of
elements from skip lists.
We discussed two different data-structure approaches to implementation
in class.
In the first approach, each node contains a Comparable element and an ArrayList of pointers. This is like the picture on the board and the applet used in class.
The ArrayList size will be between 1 and some fixed maximum - for this assignment,
that maximum will always be 10. In the second approach (from the Goodrich and Tomassia book,
which was in the PowerPoint slides), a skip list node is itself a list of nodes,
each with four pointers (up, down, left, right).
For this assignment, you are to use the first approach. Thus a Node in a SkipList has only two fields:
private T element;
private ArrayList<Node> links;
- This is an individual assignment, SkipList, in your individual repository.
- Implement public boolean insert(T e) and public boolean
remove(T e) methods.
- The header node is to have a size of MAX_LINKS (10). This is the maximum size of any
node in the skip list.
- For testing purposes, your SkipList constructor receives an integer that is used to seed the random number generator. Using a fixed seed is helpful for debugging.
1 means to add another level to the node and 0 means stop.
All numbers in the array up to and including the first zero are used in the initialization of the first
data-containing node that is inserted into the skip list.
For example, if the first numbers in the array were 1, 1, 0, 1, 0,
the first inserted node would contain 3 pointers and the second inserted node would
contain 2 pointers. If there are enough insertions so that the array runs out
(as in the first JUnit test's first skip list),
simply "wrap around" by going back to the beginning of the array.
- Here is a more concrete example. Constructing a SkipList with the seed 3226867 gives this sequence of random numbers:
[0,1,1,0,1,0,1,1,1,0,1,1,0]. Inserting the following numbers in
this order: 5,7,6,6,4, results in the following skip list:
[r [0: 4][1: 4][2: 4][3: 6][4: null][5: null][6: null][7: null][8: null][9: null]]
[4 [0: 5][1: 6][2: 6]]
[5 [0: 6]]
[6 [0: 6][1: 6][2: 7][3: null]]
[6 [0: 7][1: 7]]
[7 [0: null][1: null][2: null]]
- Testing: For testing purposes, we have added
- A method getNodesVisited() to SkipList, which returns the number of nodes that have been visited during insertion and deletion. You must increment the corresponding field every time your code visits a node in the skip list (other than the root or tail).
- A method getRoot() to SkipList, which returns the root (header) node of the SkipList. You don't need to do anything extra here.
- A method getLinks() to Node which returns an ArrayList of the node's links. You don't need to do anything extra here.
- We have provided some preliminary JUnit tests, enough for you to at least see how the interface works.
We welcome additional unit test contributions from students - just email them
to your instructor!
- It may be helpful to write a
toString()
method in the SkipList
and Node classes, which enables you to visualize the nodes and their links. Such methods
were used to produce the output shown above.
- Even better, you may find it helpful to write a graphical display of
your SkipList like shown in the applet . We'll give +10% for simple displays
showing the nodes of various heights, and even more for interactive ones
that allow the user to insert or delete elements (like the applet).
- Commit your completed code to your repository.