Introduction to Assignment 3: SEE600 Assignment3.mp4.
Due - Sunday, March 23, 2025
This is a group project of 2 or 3 students per group. The groups can be found in the document Assignment3_Groups.docx.
We want a database that is fast and uses little memory. We have limited CPU power and limited RAM. We are running real-time software (event driven) which must respond quickly to events and requests. A standard database package such as MySQL is too large and too slow for our constrained environment. Should we implement our database using std::map of the standard C++ library or construct our own custom database based on AVL trees?
A tree is perfectly balanced if it is empty or the number of nodes in each subtree differ by no more than 1. In a perfectly balanced tree, we know that searching either the left or right subtree from any point will take the same amount of time.
The search time in a perfectly balanced tree is O(log n) as the number of nodes left to consider is effectively halved with each node considered. However, to get a tree to be perfectly balance can require changing every node in the tree. This makes trying to create a perfectly balanced tree impractical.
An AVL tree does not create a perfectly balanced binary search trees. Instead it creates a height balanced binary search tree. A height balanced tree is either empty or the height of the left and right subtrees differ by no more than 1. A height balanced tree is at most 44% taller than a perfectly balanced tree and thus, a search through a height balanced tree is O(log n). Insert and delete can also be done in O(log n) time.
AVL trees work by ensuring that the tree is height balanced after an operation. If we were to have to calculate the height of a tree from any node, we would have to traverse its two subtrees making this impractical. Instead, we store the height balance (or height) information of every subtree in its node. Thus, each node must not only maintain its data and children information, but also a height balance (or height) value.
The height balance of a node is calculated as follows:
height balance = height of right - height of left of node subtree subtreeThe above formula means that if the right subtree is taller, the height balance of the node will be positive. If the left subtree is taller, the balance of the node will be negative.
For more information on the AVL tree, see the course notes of BTP500:
AVL Trees.
For an introduction to AVL Trees, see the video:
AVL Trees Introduction.
For a visualization of the algorithm for insertion and deletion with an AVL tree, see
AVL Tree Algorithm Visualization.
You have been given code for an AVL tree for both Windows and Linux. The only real difference is that the Linux version
can build a bigger tree. The code can be seen as follows:
Windows:
timer.h,
timer.cpp,
AVLTree.cpp.
Linux:
Makefile,
timer.h,
timer.cpp,
AVLTree.cpp.
Task 1: You need to clean this code a little. What could you do to facilitate the reuse of this tree in other company projects?
Even though you can see the source code, this effectively is black-box testing, because you will perform tests through the AVL Tree class interface without inspecting the code you are working with.
Now you need to write code to perform tests to see if your custom database based in the AVL tree is "better" than a database based on std::map. You have decided on the following tests in the Windows operating system:
Your test code should perform all the required tests (with the exception for the test for the memory) in one execution cycle, for both std::map and for the AVL tree. You should have separate code for Windows and Linux. Consider the following:
You will be marked out of 10 according to the following:
Does not meet expectations | Satisfactory | Good | Exceeds Expectations | |
---|---|---|---|---|
AVL Tree Cleanup 0.5 mark | Does not meet requirements | Meets the most important requirements | Meets all requirements with minor errors | Meets all requirements with no errors |
std::map test, Windows 2.0 marks | Does not meet requirements | Meets the most important requirements | Meets all requirements with minor errors | Meets all requirements with no errors |
std::map test, Linux 1.5 marks | Does not meet requirements | Meets the most important requirements | Meets all requirements with minor errors | Meets all requirements with no errors |
AVL Tree test, Windows 2.5 marks | Does not meet requirements | Meets the most important requirements | Meets all requirements with minor errors | Meets all requirements with no errors |
AVL Tree test, Linux 1.5 marks | Does not meet requirements | Meets the most important requirements | Meets all requirements with minor errors | Meets all requirements with no errors |
Questions 2.0 marks | Does not meet requirements | Meets the most important requirements | Meets all requirements with minor errors | Meets all requirements with no errors |
Please email all source code and answers to questions to: miguel.watler@senecapolytechnic.ca
Your answers to questions can be submitted in a separate document or embedded within your source code.
You will be docked 10% if your assignment is submitted 1-2 days late.
You will be docked 20% if your assignment is submitted 3-4 days late.
You will be docked 30% if your assignment is submitted 5-6 days late.
You will be docked 40% if your assignment is submitted 7 days late.
You will be docked 50% if your assignment is submitted over 7 days late.