oblem 3: In this problem we consider another alternative hashing technique which
ID: 3754463 • Letter: O
Question
oblem 3: In this problem we consider another alternative hashing technique which we will call Push and different tables. The system Shove. Here we have two hash functions hi and h2 which map elements to two di works as follows: Insertion: When we inser first table. This is easy if that slot is free. If it is not free we "push" the element a' currently stored t r into the hash table we compute h (a) and store r in that location of the there off the table and store it in the second table in location ha(r). Again if that location is not free we take the element stored there and move it to the first table continuing until we find a free slot where we don't have to push any other element off the table. 1. Argue that Search and Deletion can run in worst-case constant time using this system. 2. What can go wrong with the insertion procedure? If you identify the problem, think of possible ways to solve it.Explanation / Answer
/*package whatever //do not write package name here */
import java.io.*;
import java.util.*;
class GFG {
static int[] a = new int[10];
static int[] b = new int[10];
public static void main(String[] args){
System.out.println("enter the element x");
Scanner sc = new Scanner(System.in);
int x= sc.nextInt();
GFG obj = new GFG();
obj.push(x);
obj.show();
}
void show(){
System.out.println("first hash table ");
for(int element: a )
System.out.println(element);
System.out.println("second hash table ");
for(int element: b)
System.out.println(element);
}
void push(int x){
this.pushUtil(x,0);
}
void pushUtil(int x ,int f){
if(f==0){
int index= this.hash1(x);
if(a[index]!=0){
int y= a[index];
this.pushUtil(y,1-f);
}
else{
a[index]=x;
return;
}
}
else{
int index=this. hash2(x);
if(b[index]!=0)
{
int y =b[index];
this.pushUtil(y,1-f);
}
else{
b[index]=x;
return;
}
}
}
int hash1(int x){
x=x+23;
return x%10;
}
int hash2(int x){
x =x+37;
return x%10;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.