This assignment is to implement splay tree algorithms in python
and to test run them against regular binary search tree algorithms.
Two files,
BST.py
and SplayTree.py
,
are provided as a starting point.
Start by perusing the file BST.py
to get an idea of how the binary search tree algorithms are implemented.
You'll find that I tried to stay as close to CLRS as possible.
Here are some points worthy of note:
INORDER-TREE-WALK
is shortened to inorder
.ITERATIVE-TREE-SEARCH
is shortened to search
.TREE-MINIMUM
is shortened to minimum
.TREE-MAXIMUM
is shortened to maximum
.TREE-SUCCESSOR
is shortened to successor
.TREE-INSERT
is shortened to insert
.TREE-DELETE
is shortened to delete
.NIL
as a real node.
Every BST
object has its own NIL
node called nil
.
Some of the BSTNode
methods require nil
as an extra argument for this reason.BST.py
also contains a print
routine
for displaying binary search trees sideway for debugging purpose.
It also contains testing code in main()
so that you can simply run the script BST.py
to test the binary search tree algorithms.
Your job is to do the following.
SplayTree.py
.
These methods are
left_rotate
right_rotate
splay
search
delete
test.py
to compare
the running time of binary search tree algorithms
against splay tree algorithms. You should design test
data in such a way that it demonstrates superiority of
splay trees algorithms over regular binary search tree algorithms.README.txt
file summarizing your findings.
Do your test results agree with theory?
If not, explain the discrepancy.insert
method
has already been implemented for you! The SplayTree.py
file also contains testing code in main()
so that you can simply run the script SplayTree.py
to test the splay tree algorithms, once you have filled in all the
missing code. BST.py
file is provided so that
you can write test.py
to test and compare
the efficiency of splay trees against regular binary search trees.
Submit the completed SplayTree.py
, test.py
,
and a README.txt
file by zipping them up and emailing the
zipped file to me.