Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions