### CS323 - Skip List Homework

• Complete the Skip List implementation

• The Skip List implementation shown in class is incomplete.

Specifically, it does not have the following methods:

 delete(k): delete the entry that contains the the k firstEntry(): Return the entry with the smallest key value lastEntry(): Return the entry with the largest key value ceilingEntry(Key k): Return the entry with the smallest key value that is ≥ k floorEntry(Key k): Return the entry with the largest key value that is ≤ k upperEntry(Key k): Return the entry with the smallest key value that is > k lowerEntry(Key k): Return the entry with the largest key value that is < k

You must add these methods in the provided SkipList class to complete the implementation.

I have added some hints on how to write these methods below....

• Delete from Skip List

• The delete algorithm for a skip list was discussed on this webpage: click here

• Psuedo code:

 ``` p = findExntry(k); if (p.key != k) return(null); // Not found, don't remove /* ------------------------------------------------------------ We are at level 0 Travel up the tower and link the left and right neighbors ------------------------------------------------------------ */ while ( p != null ) { p.left.right = p.right; p.right.left = p.left; } ```

• firstEntry() and lastEntry()

• Use the head variable to find the entry with the smallest key value

• Use the tail variable to find the entry with the largest key value

• The other 4 methods

• Use findEntry() to get you near the entry you are looking for,

• Depending on the entry you are looking for, you need to traverse left or right starting at the entry that is returned by findEntry()

• Supporting programs

• The correct output should look something like this: (I make the solution by editing the skiplist)

 ```The skip list is: ******************************* -oo <---------------------------------> HIJ <-------------------------> +oo -oo <-------------------------> HAT <-> HIJ <-------------------------> +oo -oo <-> AAA <-----------------> HAT <-> HIJ <---------> XYZ <---------> +oo -oo <-> AAA <-----------------> HAT <-> HIJ <---------> XYZ <---------> +oo -oo <-> AAA <-----------------> HAT <-> HIJ <---------> XYZ <---------> +oo -oo <-> AAA <-> ABC <-> DEF <-> HAT <-> HIJ <-> KLM <-> XYZ <-> ZIJ <-> +oo ******************************* ===================================== Testing the value-added methods: ===================================== firstEntry() = (AAA,123) lastEntry() = (ZIJ,957) ceilingEntry(XYZ) = (XYZ,444) floorEntry(XYZ) = (XYZ,444) upperEntry(XYZ) = (ZIJ,957) lowerEntry(XYZ) = (KLM,987) ceilingEntry(WWW) = (XYZ,444) floorEntry(WWW) = (KLM,987) upperEntry(WWW) = (XYZ,444) lowerEntry(WWW) = (KLM,987) ===================================== Testing the remove() implementaion: ===================================== remove XXX returns: null (correct: null) ******************************* -oo <---------------------------------> HIJ <-------------------------> +oo -oo <-------------------------> HAT <-> HIJ <-------------------------> +oo -oo <-> AAA <-----------------> HAT <-> HIJ <---------> XYZ <---------> +oo -oo <-> AAA <-----------------> HAT <-> HIJ <---------> XYZ <---------> +oo -oo <-> AAA <-----------------> HAT <-> HIJ <---------> XYZ <---------> +oo -oo <-> AAA <-> ABC <-> DEF <-> HAT <-> HIJ <-> KLM <-> XYZ <-> ZIJ <-> +oo ******************************* remove XYZ returns: 444 (correct: 444) ******************************* -oo <---------------------------------> HIJ <-----------------> +oo -oo <-------------------------> HAT <-> HIJ <-----------------> +oo -oo <-> AAA <-----------------> HAT <-> HIJ <-----------------> +oo -oo <-> AAA <-----------------> HAT <-> HIJ <-----------------> +oo -oo <-> AAA <-----------------> HAT <-> HIJ <-----------------> +oo -oo <-> AAA <-> ABC <-> DEF <-> HAT <-> HIJ <-> KLM <-> ZIJ <-> +oo ******************************* remove HAT returns: 777 (correct: 777) ******************************* -oo <-------------------------> HIJ <-----------------> +oo -oo <-------------------------> HIJ <-----------------> +oo -oo <-> AAA <-----------------> HIJ <-----------------> +oo -oo <-> AAA <-----------------> HIJ <-----------------> +oo -oo <-> AAA <-----------------> HIJ <-----------------> +oo -oo <-> AAA <-> ABC <-> DEF <-> HIJ <-> KLM <-> ZIJ <-> +oo ******************************* ************ DONE ************ ```

• Turn in

• Turn your (updated) SkipList.java program file using the command:

 /home/cs323000/turnin   SkipList.java   pj2