0% found this document useful (0 votes)
83 views12 pages

Assignment Report

The document summarizes an assignment to analyze the performance of different hashing and tree-based data structures. It includes: 1) Methods to insert random strings into hash tables and measure insertion time. Cuckoo hashing showed the fastest insertion times. 2) Methods to search for random strings in hash tables and measure search time. Quadratic probing showed the fastest search times for smaller datasets. 3) Insertion and search times increased for all data structures as the dataset size increased from 2^i to 2^20 elements. Cuckoo hashing remained the fastest insertion method while Quadratic probing transitioned to the fastest search method for larger datasets. 4) Methods to insert 100,000 integers into binary

Uploaded by

ArathyUnni
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
83 views12 pages

Assignment Report

The document summarizes an assignment to analyze the performance of different hashing and tree-based data structures. It includes: 1) Methods to insert random strings into hash tables and measure insertion time. Cuckoo hashing showed the fastest insertion times. 2) Methods to search for random strings in hash tables and measure search time. Quadratic probing showed the fastest search times for smaller datasets. 3) Insertion and search times increased for all data structures as the dataset size increased from 2^i to 2^20 elements. Cuckoo hashing remained the fastest insertion method while Quadratic probing transitioned to the fastest search method for larger datasets. 4) Methods to insert 100,000 integers into binary

Uploaded by

ArathyUnni
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 12

Advanced Computing Concepts

Assignment - 1

Name: Arathy Unni


Student Id: 110061760
Email Id: unnia@uwindsor.ca

“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.

• Code Path: AccAssignmentNumberOne/src/HashTable/HashTableInsertDelete.java


• Java File Name: HashTableInsertDelete.java
• Methods: main() and GenerateRandomNumbers()
• Variables Used:
i. randomNumber: To assign the generated random number before inserting into
the hash table
ii. insertionStartTime: To assign the start time of insertion of each element
iii. timeforInsertion: To assign the difference of the insertion start time and end
time
iv. averageTimeForInsertion: To assign the average time for each insertion
v. numberOfStrings: To assign the number of strings to be inserted to the hash
table
vi. hashTable: To point to the hash table
• Average time for each insertion:
i. Number of strings generated for inserting into the hash table: 20
ii. Average time for each insertion: 1785 nanoseconds

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.

• Code Path: AccAssignmentNumberOne/src/HashTable/HashTableInsertDelete.java


• Java File Name: HashTableInsertDelete.java
• Methods: main() and GenerateRandomNumbers()
• Variables Used:
i. searchStartTime: To assign the start time of search operation
ii. numberOfStrings: To assign the number of strings inserted into the hash table
iii. str: To assign the random string which is to be checked against the hash table
iv. timeforSearch: To assign the difference of search start time and end time
v. averageTimeForSearch: To assign the average time of each search
vi. hashTable: To point to the hash table
• Average time for each search:
i. Number of strings generated to be inserted into the hash table: 20
ii. Average time for each search: 90285 nanoseconds

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.

• Code Path: AccAssignmentNumberOne/src/HashTable/CuckooHashTable.java


AccAssignmentNumberOne/src/HashTable/QuadraticProbingHashTable.java
AccAssignmentNumberOne/src/HashTable/SeparateChainingHashTable.java
• Java File Name: CuckooHashTable.java
QuadraticProbingHashTable.java
SeparateChainingHashTable.java
• Methods: main(), insert(), contains(), remove()
• Variables Used:
a. CuckooHashTable.java
i. cuckooHashTable: 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

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

• Average time for each insertion in Cuckoo, QuadraticProbing and SeparateChaining:


• Observations for insertion operation of n elements where n = 2i, i = 1, …, 20.:
i. SeparateChaining takes more time for insertion operation among all the three
hashing techniques
ii. Cuckoo hashing takes the least time for insertion operation among all the three
hashing techniques
iii. Upon increasing the number of elements, it is observed that the
QuadraticProbing is taking lesser time compared to other two hashing
techniques

• Average time for each search in Cuckoo, QuadraticProbing and SeparateChaining


• Observations for search operation of n elements where n = 2i, i = 1, …, 20.

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.

4. Use the Java classes BinarySearchTree, AVLTree, RedBlackBST, SplayTree given in


class. For each tree:
a. Insert 100,000 integer keys, from 1 to 100,000 (in that order). Find the average
time for each insertion.
• 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: insert(), put()
• Variables Used:
a. AVLTree.java
i. avlTree: To point to the AVL tree
ii. startInsert: To assign the start time of inserting node to AVL tree
iii. timeForInsert: To assign the difference of start and end times of
inserting node to AVL tree
iv. averageTimeForInsert: To assign the average time of each insertion
b. BinarySearchTree.java
i. binarySearchTree: To point to the BinarySearchTree
ii. startInsert: To assign the start time of inserting node to
BinarySearchTree
iii. timeForInsert: To assign the difference of start and end times of
inserting node to BinarySearchTree
iv. averageTimeForInsert: To assign the average time of each insertion
c. RedBlackBST.java
i. redblacktree: To point to the RedBlack tree
ii. startInsert: To assign the start time of inserting node to RedBlack tree
iii. timeForInsert: To assign the difference of start and end times of
inserting node to RedBlack tree
iv. averageTimeForInsert: To assign the average time of each insertion
d. SplayTree.java
i. splayTree: To point to the Splay tree
ii. startInsert: To assign the start time of inserting node to Splay tree
iii. timeForInsert: To assign the difference of start and end times of
inserting node to Splay tree
iv. averageTimeForInsert: To assign the average time of each insertion

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.

• 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: 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. startRemove: 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

5. For each tree:


a. Insert 100,000 keys between 1 and 100,000. Find the average time of each
insertion.
• 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: insert(), put()
• Variables Used:
a. AVLTree.java
i. avlTree: To point to the AVL tree
ii. startInsert: To assign the start time of inserting node to AVL tree
iii. timeForInsert: To assign the difference of start and end times of
inserting node to AVL tree
iv. averageTimeForInsert: To assign the average time of each insertion
b. BinarySearchTree.java
i. binarySearchTree: To point to the BinarySearchTree
ii. startInsert: To assign the start time of inserting node to
BinarySearchTree
iii. timeForInsert: To assign the difference of start and end times of
inserting node to BinarySearchTree
iv. averageTimeForInsert: To assign the average time of each insertion
c. RedBlackBST.java
i. redblacktree: To point to the RedBlack tree
ii. startInsert: To assign the start time of inserting node to RedBlack tree
iii. timeForInsert: To assign the difference of start and end times of
inserting node to RedBlack tree
iv. averageTimeForInsert: To assign the average time of each insertion
d. SplayTree.java
i. splayTree: To point to the Splay tree
ii. startInsert: To assign the start time of inserting node to Splay tree
b. Repeat #4.b.
• 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(), 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. redblacktree: To point to the RedBlack tree
ii. startSearch: To assign the start time of searching a node from RedBlack
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
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. 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.

Insertion: SplayTree < RedBlackBST < AVLTree < BinarySearchTree.


Searching: AVLTree< RedBlackBST< SplayTree<BinarySearchTree
Deletion: SplayTree < RedBlackBST < AVLTree < BinarySearchTree

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.

You might also like