## Description

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 copyand-paste that code to your HTable class: template int HTable::hashfun(const T& 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 LinkedList 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. SUBMISSION Make sure your code works with the files supplied, and DO NOT change them. For marking, we will add the main file to the project and compile it using the makefile, together with your own files. If it does not compile or run, your mark will be zero. Your submission should be made using the Assignments section of the course Blackboard site. Incorrectly submitted assignments will not be marked. You should provide all your files. Also, if necessary, provide a readme.txt file containing any instructions for the marker. Each program file should have a proper header section including your name, course and student number, and your code should be properly documented. Compress all your files into a single .zip file, using your student number as the filename. For example, if your student number is c9876543, you would name your submission: c9876543.zip If you have attempted the Bonus Requirement (or you are a 6120 student), please include a blank text file in the same folder as your source files, simply called Bonus.txt – this is to make it clear to the marker that you are attempting this. Submit by selecting the Assignment 2 link that will be found in the Assessment section on Blackboard. Remember that your code should compile and run correctly using GNU C++. Test it using Cygwin. Late submissions are subject to the rules specified in the Course Outline. This assignment is worth 15.0 marks of your final result for the course. SAMPLE OUTPUT CES236-7DXQJX2+Alex@CES236-7DXQJX2 /home/Ass3-S2-2021 $ ./assignment3.exe ================== BINARY SEARCH TREE ================== Initial tree: (2AJX-349U-JNJE-9DSM,92) (2ELF-P6UX-5EWP-5ZGR,87) (35GY-CMRP-BPBCNNPN,27) (3T2Q-ADF5-4YUK-RMTA,27) (3Y8Y-6XM2-98C6-Z6EB,67) (4MC2-XUUU-FR35-8T8Y,91) (4Q86-XDM4-FZ99-F3KG,46) (4WQF-5UJX-JM7N-22WR,38) (57Q5-KRVS-SXMX-TCG9,25) (5XH5-EH3CBFZJ-ALGY,38) (5XWN-VXPN-HXBA-3KZZ,8) (5Y8U-3AQS-ZGMX-S595,55) (5ZXS-58Y5-33J2- PYMF,99) (6BYN-5CQY-PPGC-B2AY,47) (6C37-LAHZ-NFL3-ALD7,88) (6FFE-7458-G3MY-G2JA,89) (6MG8-NPWY-MMDN-682C,11) (7MMB-D3DV-4MDY-VQS6,56) (8XEB-XMBB-2X5B-3LFG,26) (94UA-UZ57- 2SBX-NR6A,41) (9JGS-8PRH-7KTX-62Q6,48) (9MAG-G3DV-MXVP-ATME,82) (9RYN-VW77-TQ53- RPVU,77) (A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Q,28) (P5AZ-8C6U-STWB-W2X3,56) (PWEU-T45F5GPH-FG3V,7) (Q2S4-P2NQ-HKL9-VND5,94) (QNXM-7XEL-CHA9-TZJB,92) (QR5V-MXEY-XBJA5MPD,90) (R89W-386K-YZ5P-LFVN,95) (RZ4K-X33Z-AN3P-T8EM,4) (S3EZ-JWDZ-RRQE-ZV7W,55) (S965-H5LA-VHC8-DUHH,69) (STX9-DX83-Y4E6-Y7QW,37) (TGJ2-LCNP-JVQ2-XQXV,68) (UD5C-9YUF7MC6-QRZE,36) (UHVR-U9Z6-P63M-E7XA,36) (V364-N8UB-P7SJ-RKH2,92) (VDMA-GCSJ-LUT5- TJ7Z,95) (VKGN-WTH6-HWEU-Y3FQ,65) (VKTN-PE4M-74QL-JBQR,39) (VNLX-VUZX-BRJK-WN8Y,27) (W8GH-DDE5-HXWN-4HPG,11) (WPFR-TYJQ-8LLY-RZYY,24) (WVF3-AZ7Y-N9W9-5NUK,36) (XCBU-9L3QZXPS-42SL,50) (XQTS-2RSD-CWX9-M7CS,3) (Y7T5-G2E3-58AT-U6F3,13) (YKM3-YKMG-8NSGJSTA,52) (YM62-YJ6X-8ZVX-DDWN,14) (Z7C4-8UZL-GNLF-AMTJ,3) (ZF96-2XH9-665N-AWC6,40) (ZPXP-MP4B-9HR9-WMHR,67) (ZU5J-FF72-RE4L-VEYS,20) (ZVS7-3TQB-9C8H-BSP4,70) (ZZLD-Q4FCBK2V-MS5K,41) Adding and removing… Time elapsed: 1.64 seconds Time per ins/del operation: 0.780952 milliseconds. There are 100 types of parts and 4907 parts in total. There are 11 types of parts with less than 10 in inventory. ================== HASH TABLE ================== Initial hash table: (3Y8Y-6XM2-98C6-Z6EB,67) (HEYY-5AFH-DEX7-ESPS,100) (5ZXS-58Y5-33J2- PYMF,99) (FQAJ-GNA8-TN93-M3KL,41) (RZ4K-X33Z-AN3P-T8EM,4) (4MC2-XUUU-FR35-8T8Y,91) (ZZLD- Q4FC-BK2V-MS5K,41) (TGJ2-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6UX-5EWP-5ZGR,87) (NBPW-68T3-K6BB-GFUG,63) (JRKP-RPXW-JHJF-Q3BE,46) (ZVS7-3TQB-9C8H-BSP4,70) Adding and removing… Time elapsed: 0.61 seconds Time per ins/del operation: 0.290476 milliseconds. There are 100 types of parts and 4907 parts in total. There are 11 types of parts with less than 10 in inventory. The program has finished. CES236-7DXQJX2+Alex@CES236-7DXQJX2 /home/Ass3-S2-2021 $ Good Luck Dan and Alex v1.0 2021-10-08