Module Code: SENG1120/6120
Module Subject: Discipline of Computing and Information Technology
Assignment 3
INTRODUCTION
In lectures, we have discussed the benefits of using binary search trees and hash tables to store information. In this assignment you will implement both and compare their performances in terms of speed of access.
ASSIGNMENT TASK
You are in charge of inventory management support in a factory. You are required to create binary search tree and hash table data structures to store instances of a class MechPart. Both data structures should have functions to add, remove, display, overloaded operators, among others. The classes MUST be implemented as class templates. The binary search tree class must be called BSTree and will use as nodes instances of BTNode. The hash table class must be named HTable.
You will be provided a demo file, a MechPart class, and a text file with a list of part codes and quantities, and your classes need to interface with them. The binary search tree contents must be printed using an inorder traversal. The hash table class must store the instances of MechPart in an array of size 5,000, and the contents can be printed from position 0 to n-1, but only for those positions that contain a valid entry. The hash function to be used is provided below. You can copy-and-paste that code to your HTable class:
template <typename value_type>
int HTable<value_type>::hashfun(const value_type& value) { int position = 0;
string temp = value.get_code();
for (int i=0; i<(int)temp.length(); i++)
{
position += (i+1) * (i+1) * temp.at(i);
}
return position % TABLE_SIZE;
}
A few points:
- As you implement the classes, you will notice that even though HTable and BSTree are generic class templates, they only work with MechPart. That is, some public methods in the HTable and BSTree classes refer directly (and only make sense) with MechPart.
- That was a design decision for this assignment. We could get around that, but it would make the assignment extremely challenging for most students.
- When you implement the classes, start small and then add more and more functionality as you go. Start by implementing BSTree and comment out everything in the demo file and in the makefile that refers to HTable. This way, you can test your code as you go. Once BSTree is working, you can move on to HTable.
- The solution provided in the next page is the result that you should get if your code is correct. The computational time will differ, as this was run in my personal computer, but the hash table will be faster than the binary search tree for sure.
- What does the demo code do? The demo code reads the code and quantity of 100 mechanical parts from a file and populates the binary search tree. Then, it removes and adds some of the elements 100,000 times, and prints some statistics about the process. After that, it does the same for the hash table, and the program finishes.
SENG6120 students (or for bonus marks): The 100 mechanical parts in the input file provided do not induce any collisions in a hash table with 5,000 positions. If you reduce the size of the array in the hash table to 300 positions, however, there will be 16 collisions.
Your task is to create a hash table with buckets that eliminates the problem of collisions by having a linked list in each position of the array. This way, if two or more elements map to the same position of the array, they are stored as different nodes in the linked list for that position. Test you approach by reducing the size of the array to 300 and making sure that all 100 elements are stored correctly, and the demo provided still works.
“You can order SENG1120/6120 : Discipline of Computing and Information Technology Assignment from our service and can get a completely high-quality custom paper. Our service offers any of the SENG1120/6120 Academic paper written from scratch, according to all customers’ requirements, expectations and highest standards.”
100% Plagiarism Free
24X7 Customer Support
Multiple Revisions
100% Confidential
On-time Delivery
500+ Experts