Question: Given an array A [ 1 . n n ] we want to find the element which occurs in this array with the highest frequency

Given an array A[1.nn] we want to find the element which occurs in this array with the highest frequency (i.e., the mode). We decide to use hashing for this purpose. We shall use hashing with chaining. But to calculate frequencies, we need to change the insert function. If the key to be inserted is already present in the hashtable, then we simply increment its frequency by 1. If key k is not already present, then we proceed as usual to create a new entry to be added to the linked list originating at htable[h(k)]. In this case, hashobject will have three fields:
struct Hashobject
int key;
int freg =1
Hashobject *?next;
}
Hashobject htable[n
int hfint k return {:(k**7193%n);}
You
have.to write (using CC++/Java/precise pseudocode):
void insert(int key)
}
Your insert function will first find the location in hash table ), then walk through the linked list emanating from that slot. If it finds k in the linked list, it increments its frequency. Else, it inserts a new node containing key k at the end of the linked list.
Given an array A[1..n] we want to find the element which occurs in this array with the highest frequency (i.e., the mode). We decide to use hashing for this purpose. We shall use hashing with chaining. But to calculate frequencies, we need to change the insert function. If the key to be inserted is already present in the hashtable, then we simply increment its frequency by 1. If key k is not already present, then we proceed as usual to create a new entry to be added to the linked list originating at htable[h(k)]. In this case, hashobject will have three fields:
struct Hashobject
int key;
int freg =1;
Hashobject *next;
}
Hashobject htable[n];
int h(int k){ return ((:k**7193%n}; }
You have to write (using CC++/Java/precise pseudocode):
void insert(int key)
}
Your insert function will first find the location in hash table ), then walk through the linked list emanating from that slot. If it finds k in the linked list, it increments its frequency. Else, it inserts a new node containing key k at the end of the linked list.
 Given an array A[1.nn] we want to find the element which

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!