Assignment Report
Assignment Report
Assignment - 1
“I confirm that I will keep the content of this assignment confidential. I confirm that I have not
received any unauthorized assistance in preparing for or writing this assignment. I acknowledge
that a mark of 0 may be assigned for copied work.” – Arathy Unni, 110061760
1. Within a Java class, write a method that creates n random strings of length 10 and inserts
them in a hash table. The method should compute the average time for each insertion.
2. Write another method that finds n random strings in the hash table. The method should
delete the string if found. It should also compute the average time of each search.
3. Repeat #1 and #2 with n = 2i, i = 1, …, 20. Place the numbers in a table and compare the
results for Cuckoo, QuadraticProbing and SeparateChaining`. Comment on the times
obtained and compare them with the complexities as discussed in class.
b. QuadraticProbingHashTable.java
i. quadraticProbingHT: The point to the hash table
ii. hashTable: To point to a secondary hash table to store the values that needs
to be searched
iii. startInsert: To assign the start time of insertion of each element
iv. averageTimeForInsert: To assign the difference of the insertion start time and
end time
v. averageInsert: To assign the average time for each insertion
vi. startSearch: To assign the start time of each search
vii. averageTimeForSearch: To assign the difference of the search start time and
end time
viii. averageSearch: To assign the average time for each search operation
c. SeparateChainingHashTable.java
i. seperateChainingHT: The point to the hash table
ii. hashTable: To point to a secondary hash table to store the values that needs
to be searched
iii. startInsert: To assign the start time of insertion of each element
iv. averagetime: To assign the difference of the insertion start time and end time
v. averageInsert: To assign the average time for each insertion
vi. startSearch: To assign the start time of each search
vii. averageTimeForSearch: To assign the difference of the search start time and
end time
viii. averageSearch: To assign the average time for each search operation
i. SeparateChaining takes more time for search operation among all the three hashing
techniques
ii. At the highest order of 2 (from i=14 to 20) for n, the Cuckoo hashing takes the least
time among all the three hashing techniques
iii. At the lower order of 2 (from i=1 to 5) for n, the QuadraticProbing hashing takes
the least time among the all three hashing techniques
Conclusion:
We can conclude that SeparateChaining is not a feasible hashing technique for both insertion and
search operations since it takes the most time among all the three hashing techniques. Cuckoo
hashing technique is preferred for insertion operation and Quadratic probing works the best for
search operation when the number of elements is low and as the number of elements goes on to
higher values Cuckoo hashing is the best hashing technique.
b. Do 100,000 searches of random integer keys between 1 and 100,000. Find the
average time of each search.
• Code Path: AccAssignmentNumberOne/src/Trees/AVLTree.java
AccAssignmentNumberOne/src/Trees/BinarySearchTree.java
AccAssignmentNumberOne/src/Trees/RedBlackBST.java
AccAssignmentNumberOne/src/Trees/SplayTree.java
• Java File Name: AVLTree.java
BinarySearchTree.java
RedBlackBST.java
SplayTree.java
• Methods: contains(), get()
• Variables Used:
a. AVLTree.java
i. avlTree: To point to the AVL tree
ii. startSearch: To assign the start time of searching a node in AVL tree
iii. timeForSearch: To assign the difference of start and end time of search
operation
iv. averageTimeForSearch: To assign the average time of each search
operation
b. BinarySearchTree.java
i. binarySearchTree: To point to the BinarySearchTree
ii. startSearch: To assign the start time of searching a node in
BinarySearchTree
iii. timeForSearch: To assign the difference of start and end time of search
operation
iv. averageTimeForSearch: To assign the average time of each search
operation
c. RedBlackBST.java
i. startSearch: To assign the start time of searching a node in RedBlack
tree
ii. timeForSearch: To assign the difference of start and end time of search
operation
iii. averageTimeForSearch: To assign the average time of each search
operation
iv. redblacktree: To point to the RedBlack tree
d. SplayTree.java
i. splayTree: To point to the Splay tree
ii. startsearch: To assign the start time of searching a node in Splay tree
iii. timeForSearch: To assign the difference of start and end time of search
operation
iv. averageTimeForSearch: To assign the average time of each search
operation
c. Delete all the keys in the trees, starting from 100,000 down to 1 (in that order).
Find the average time of each deletion.
c. Repeat #4.c but with random keys between 1 and 100,000. Note that not all the
keys may be found in the tree.
• Code Path: AccAssignmentNumberOne/src/Question5/AVLTree.java
AccAssignmentNumberOne/src/Question5/BinarySearchTree.java
AccAssignmentNumberOne/src/Question5/RedBlackBST.java
AccAssignmentNumberOne/src/Question5/SplayTree.java
• Java File Name: AVLTree.java
BinarySearchTree.java
RedBlackBST.java
SplayTree.java
• Methods: contains(), remove(), delete()
• Variables Used:
a. AVLTree.java
i. avlTree: To point to the AVL tree
ii. startRemove: To assign the start time of removing a node from AVL
free
iii. timeForRemoval: To assign the difference of start and end time of
removal operation
iv. averageTimeForRemoval: To assign the average time of each removal
operation
b. BinarySearchTree.java
i. binarySearchTree: To point to the BinarySearchTree
ii. startRemove: To assign the start time of removing a node from
BinarySearchTree
iii. timeForRemoval: To assign the difference of start and end time of
removal operation
iv. averageTimeForRemoval: To assign the average time of each removal
operation
c. RedBlackBST.java
i. redblacktree: To point to the RedBlack tree
ii. startDelete: To assign the start time of removing a node from RedBlack
tree
iii. timeForRemoval: To assign the difference of start and end time of
removal operation
iv. averageTimeForRemoval: To assign the average time of each removal
operation
d. SplayTree.java
i. splayTree: To point to the Splay tree
ii. startRemove: To assign the start time of removing a node from Splay
tree
iii. timeForRemoval: To assign the difference of start and end time of
removal operation
iv. averageTimeForRemoval: To assign the average time of each removal
operation
6. Draw a table that contains all the average times found in #4 and #5. Comment on the
results obtained and compare them with the worst-case and average-case running times
of each operation for each tree. Which tree will you use in your implementations for real
problems? Note: you decide on the format of the table (use your creativity to present the
results in the best possible way).
• Average time calculation for insertion, search and deletion (1 to 100000 sorted
values)
• Average time calculation for insertion, search and deletion for random values
Observation on the average values calculated for Insert, Search and Deletion operation for Sorted
and Random values:
Sorted Values:
For insertion Splay tree is taking least amount of time, followed by the RedBlackBST. For
searching AVL tree is taking the least amount of time and BinarySearchTree is taking more time.
For Deletion operation Splay tree takes least amount of time, followed by the RedBlackBST.
BinarySearchTree takes the last position.
Random Values:
For insertion RedBlackBST took less time, followed by BinarySearchTree. The same order stands
for Search operation as well. Whereas Splay tree took the least amount of time for deletion
operation and RedBlackBST took the maximum time.
Insertion: RedBlackBST<BinarySearchTree<SplayTree<AVLTree
Searching: RedBlackBST<BinarySearchTree<AVLTree<SplayTree
Deletion: SplayTree<BinarySearchTree<AVLTree<RedBlackBST
Conclusion:
Therefore, in real world problems I personally would opt SplayTree for deletion operation of both
sorted and random values since plays the best role. For the insertion and search operation of
random values RedBlackBST plays the best role. Splay tree is the best for insertion of sorted
values and AVL tree is the best for searching of sorted values.