Data Structures and Algorithms.
Make sure to use C++ language. Q1 ) In this question, you will explore the tradeoff between the average number of comparisons for a successful search of an element in a hash table vs. the load imbalance index. It is logical to expect that as the hash table size (the size of the array of linked lists representing the hash table) grows, the length of each of the linked lists reduces: as a result, the number of comparisons that would be needed to search for any element is likely to reduce. On the other hand, as we fix the number of elements to store in a hash table, the load imbalance index (the ratio of the sum of the maximum and minimum lengths of the linked lists and the difference between the maximum and minimum lengths of the linked lists; see the slides for the formulation and details) is expected to increase with increase in the hash table size. Thus, for a fixed number of elements to store in a hash table, as we increase the hash table size, the average number of comparisons for a successful search is expected to decrease and the load imbalance index is expected to increase. As part of your solution, you will explore/quantify the above tradeoff. You are given the code featuring the implementation of a hash table as an array of singly linked lists. The main function is already coded to create an array of size 100,000 with the maximum value per element being 50,000. You will try 20 different values for the hash table size ranging from 11 to 2,287 as given in the code (note the array of hash table size is already created for you in the main function). For each hash table size, you will run 25 trials. You are required to implement the functions FindAvgNumComparisonsSuccessfulSearch( ) and ComputeLoadImbalanceIndex( ) in the Hashtable class. The main function is coded in such a way that these two functions are called for each of the trials for a certain hash table size and the average of the average number of comparisons for a successful search and the average load imbalance index are computed and printed for each value of the hash table size. Take a screenshot of the output displaying the average number of comparisons for a successful search and the load imbalance index for different values of the hash table size. Plot two Excel charts (X-Y plots) that features the values for the hash table size in X-axis and the values for the average number of comparisons for a successful search and the average load imbalance index in the Y-axes. Use the trend line option in Excel for each of these plots and determine a power function- based relation between the metric on the Y-axis and the hash table size in the X-axis. Display the power function-relation as well as the R2 value for the fit in the Excel plots. Q2) Design and implement an algorithm to determine the next greater element of an element in an array in Θ(n) time, where ‘n’ is the number of elements in the array. You could use the Stack ADT for this purpose. The next greater element (NGE) for an element at index i in an array A is the element that occurs at index j (i < j) such that A[i] < A[j] and A[i] ≥ A[k] for all k [i+1…, j-1]. That is, index j (j > i) is the first index for which A[j] > A[i]. If no such index j exists for an element at index i, then the NGE for the element A[i] is considered to be -1. For example: if an array is {1, 15, 26, 5, 20, 17, 36, 28}, then the next greater element (NGE) of the elements in the array are as follows: 1 15 15 26 26 36 5 20 20 36 17 36 36 -1 28 -1 Note: Your code need not determine and print the elements and their NGE values in the same order of the appearance of the elements in the array. An out of order print is also acceptable as long as the correct NGE for an element is printed out. For example, the following out of order print for the above array is also acceptable. 1 15 15 26 5 20 17 36 20 36 26 36 28 -1 36 -1 You are given a code file to run the algorithm on a smaller array (of size 10 integers) and print the output (i.e., the NGE for each element in the array, in the order determined by your algorithm). You should implement the algorithm in the main function itself and make use of the Stack stack object as part of the processing needed by your algorithm. You are given the doubly linked list-based implementation code for Stack and there is no need to make any changes in the Stack class.