CODE:
class HashTable_LinkedList_ContinuousSeqVersion{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int numElements;
System.out.print("Enter the number of elements you want to store in
the hash table: ");
numElements = input.nextInt();
int maxValue;
System.out.print("Enter the maximum value for an element: ");
maxValue = input.nextInt();
int hashTableSize;
System.out.print("Enter the size of the hash table: ");
hashTableSize = input.nextInt();
int numTrials;
System.out.print("Enter the number of trials: ");
numTrials = input.nextInt();
Random randGen = new Random(System.currentTimeMillis());
int totalLongestSequenceLength = 0;
long totalDetectiontime = 0;
for (int trials = 1; trials <= numTrials; trials++){
long startTime = System.currentTimeMillis();
Hashtable hashTable = new Hashtable(hashTableSize);
int array[] = new int[numElements];
for (int index = 0; index < numElements; index++){
array[index] = 1 + randGen.nextInt(maxValue);
hashTable.insert(array[index]);
}
int longestSubsequenceLength = 0; // longest sequence length for theparticular trial
// Implement your algorithm here and find the longestSequenceLength for the array
int seqLen = 0;
for(int i = 1;i<maxValue;i++){
if(hashTable.hasElement(i)){
seqLen++;
}else{
if(seqLen > longestSubsequenceLength){
longestSubsequenceLength = seqLen;
}
seqLen = 0;
}
}
long endTime = System.currentTimeMillis();
totalLongestSequenceLength += longestSubsequenceLength;
totalDetectiontime += (endTime - startTime);
}// trials
System.out.println("Average Longest Subsequence Length: "+(((double)
totalLongestSequenceLength)/numTrials));
System.out.println("Average detection time (milliseconds):
"+(((double) totalDetectiontime)/numTrials));
}
}
In this project, you will work on the algorithm (discussed in Module 1) to determine the...
I need help with this in JAVA. please help me. Thank you. In this project. you are given a unimodal array of n integer and your task is to find the maximum integer in the array in theta(logn) time. An unimodal array of integers is an array with entries that monotonically increase up to the maximum integer value and then monotonically decrease for the rest of the array. For example: (2, 5, 8, 9, 12, 15, 21, 17, 10, 4)...
Project Description: In this project, you will combine the work you’ve done in previous assignments to create a separate chaining hash table. Overview of Separate Chaining Hash Tables The purpose of a hash table is to store and retrieve an unordered set of items. A separate chaining hash table is an array of linked lists. The hash function for this project is the modulus operator item%tablesize. This is similar to the simple array hash table from lab 5. However, the...
Coded in Java. Also advised to use class java.util.HashMap Problem 1 You are given an array A of integers and an integer k. Implement an algorithm that determines, in linear time, the smallest integer that appears at least k times in A. Problem 2 You are given an array A of integers and an integer k. Implement an algorithm that determines in linear time whether there are two distinct indices i and j in the array such that A[i] =...
JH: Student Name: 4) Given the following array, do the following (show all the work). A (56, 89, 23, 58, 22, 11, 45, 48, 90) (a - 5 pts) Construct a hash table for the given array using the hash function H(K)- K mod 5 (b- 4 pts) Determine the average number of comparisons for a successful search using the hash table of (c -3 pts) What is the worst case number of comparisons for an unsuccessful search in the...
Suppose you are given an array of n integers ai, az, ..., an. You need to find out the length of its longest sub-array (not necessarily contiguous) such that all elements in the sub-array are sorted in non-decreasing order. For example, the length of longest sub-array for (5, 10, 9, 13, 12, 25, 19, 30) is 5 and one such sub-array is (5, 10, 13, 19, 303. Note you may have multiple solutions for this case. Use dynamic programming to...
Suppose you are given an array of n integers a1, a2, ..., an. You need to find out the length of its longest sub-array (not necessarily contiguous) such that all elements in the sub-array are sorted in non-decreasing order. For example, the length of longest sub-array for {5, 10, 9, 13, 12, 25, 19, 70} is 6 and one such sub-array is {5, 10, 13, 19, 70}. Note you may have multiple solutions for this case. Use dynamic programming to...
I need help In the lecture you got acquainted with the median algorithm, which calculates the median of an unsorted array with n∈N elements in O (n). But the algorithm can actually do much more: it is not limited to finding only the median, but can generally find the ith element with 0≤i <n. Implement this generic version of the median algorithm by creating a class selector in the ads.set2.select package and implementing the following method: /** * Returns the...
Instead of using a linked list to resolve collisions, as in separate chaining, use a binary search tree. That is, create a hash table that is an array of trees. To display a small tree-based hash table, you could use an inorder traversal of each tree. The advantage of a tree over a linked list is that it can be searched in O(logN) instead of O(N) time. This time savings can be a significant advantage if very high load factors...
Sorting Sort the following array using the quick sort algorithm: (4 Marks) a. 12 26 8 9 7 0 4 Pivot selection is defined to be the first element of each sub-list. Show the array before and after each quicksort round (when the array is partitioned after placing the pivot at its correct position). Also, clearly highlight the pivot in each partition b. Consider an unsorted array of integers of size n. Write a Java program to arrange the array...
for java 4. Instead of using a linked list to resolve collisions, as in separate chaining, use a binary search tree. That is, create a hash table that is an array of trees. To display a small tree-based hash table, you could use an inorder traversal of each tree. The advantage of a tree over a linked list is that it can be searched in O(logN) instead of O(N) time. This time savings can be a significant advantage if very...