120 likes | 131 Vues
This project aims to create a data structure with O(log(N)) insertion, deletion, and random access. The implementation and empirical testing of the data structure's general case runtime will be conducted.
E N D
A Logarithmic Randomly Accessible Data Structure Tom Morgan TJHSST Computer Systems Lab 2006-2007
Purpose • To create a data structure with: • O(log(N)) insertion • O(log(N)) deletion • O(log(N)) random access • To implement the data structure and empirically test the general case run time • To prove the data structure's worst case run time
Background • Dynamic Arrays • O(N) insertion • O(N) deletion • O(1) random access • Red-Black Trees • O(log(N)) insertion • O(log(N)) deletion • not randomly accessible • Splay Trees • amortized O(log(N)) insertion • amortized O(log(N)) deletion • not randomly accessible
The Basic Algorithm • Similar to binary search tree • Places values only at the leaves • Each node keeps track of the number of leaves below it • O(log(N)) on all operations in a random case, but not a sequential one • Balancing is underway
Balancing Techniques • When performing any operation, if not balanced: • Shift one element from bigger side to smaller side • Shift half of bigger side to smaller side • Find best cutoff point along nearest side to smaller side (if right is bigger, the left part of it) and shift over corresponding sub-tree
Red Black Tree • Each node is either red or black • The path from the root to each leaf contains the same number of black nodes • A red node may not have a red parent • Absurd amount of cases
Splay Tree • Standard binary search tree but for splay function • Splay function is called everytime a node is accessed • Splay function rotates accessed node up to the root position
Testing • Data structure implemented in Java as a class • Test various operations and their runtime using a separate testing program in Java, which uses the class • Tester allows for both random and ordered insertion and deletion • Balanced tree compared to TreeSet and ArrayList
Results: Pre-Red Black Tree • A tree that allows for insertion, deletion and random access • All operations are logarithmic on the random case • Three separate balancing techniques which vary in terms of effectiveness of balancing and time taken by the balancing • None of the balancing techniques are perfect as of now
Results: Red Black Tree • Started making randomly accessible but quickly encountered errors • Insertion works fine but deletion appears to throw off properties • Have added numerous testing and analysis functions to no avail • Work suspended in favor of Splay Tree
Results: Splay Tree • The Splay Tree is fully functional • Has complete random access functionality • Works with Java's templates • Made compliant with Collection and AbstractList • Added depth-first search iterator, allowing O(N) access of all elements in sequence