Assigned: Wednesday, February 27
Due: Friday, March 8 (Monday after Spring Break counts as just one late day)
Synopsis: This is our first (and probably only) programming assignment. You will implement a dynamic set class using skip lists and evaluate their performance.
Details: You are to implement a simple dynamic set class based on skip lists. This will be a toy class; the elements it will store have keys but no satellite data. Your implementation should support the following interface:
typedef struct _sl_element
struct _sl_element *next;
struct _sl_element *prev;
* You design the underlying data structure and any private methods
// Constructor takes the probability of adding element to next list
// return the minimum and maximum elements in a set:
sl_element * min() const;
sl_element * max() const;
// return the next and previous elements in the sorted order:
sl_element * succ(sl_element *el) const;
sl_element * pred(sl_element *el) const;
// Return pointer to element with a given key, or NULL if none exists:
sl_element * search(float key) const;
// Insert an element with the given key and data, return ptr to element:
sl_element * insert(void *data, float key);
// Delete the given element:
void remove(sl_element *el);
A sample implementation using a simple linked list (skip lists without the skip) is provided on the course web page. You are welcome to build on this code or write your own; however, you are not allowed to reuse code from previous coursework. You should also not use high-level C++ constructs (templates, etc) nor standard libraries (STL, etc). The idea is that you should code skip lists at a low level from scratch.
Your implementation should compile and run under MS Visual C++ 6.0. You should compile it as a library named skiplist.lib; we will link a test program to your library. You can use the sample workspace and project files as a template for this.
Evaluation: You should also write your own test program to analyze the asymptotic performance of your library. Create skip lists ranging from (say) 1,000 to 1,000,000 random elements and analyze the average time taken for inserts and (unsuccessful) searches. Also examine how running time is affected by the probability p used to construct the skip list. Use MS Excel (or a similar program) to plot running time as n and p vary.
Turning in your assignment: You should mail Pavel Sorokin (email@example.com) a single attachment containing a zip file, which contains a single directory, which in turn contains your source code (.cpp files), headers (.h files), workspace (.dsw files), and projects (.dsp files). The idea is that Pavel should be able to unzip your attachment, open the resulting folder, and double-click on your .dsw file to open everything he needs to run and grade your program. You should try this yourself before turning it in! If we have trouble compiling or running your code, it will reduce your grade. Be sure to clean the directory (Clean under the Build menu for each project) to remove all object files, executables, etc. before zipping and mailing the directory to Pavel.
You should bring in a hard copy of your evaluation to hand in at the beginning of class as usual. This should be a 1-2 page document with some plots and a brief discussion of how you did your analysis and what you learned.
20% Technical issues: code compiles, easy to read, well-documented, etc.
40% Successful implementation of skip lists
40% Testing and analysis
Note that it is possible to do a good job and get full credit for testing and analysis even if skip lists are not completely successfully implemented.
Extra credit: You can get 50% extra credit by implementing the same dynamic set interface built on a binary search tree implementation, and analyzing the resulting running time on random insertion as described above. The same coding principles apply: your implementation should be simple, low-level, and entirely your original code. Ask if you have any questions about the extra credit.
Errata and addenda: Be sure to check the course web page often for corrections and clarifications. These will be indicated in red.