Assig 7
Assig 7
#include <stdio.h>
#include <math.h>
// Division Method
// Mid-Square Method
key /= 100;
void insert_and_check_collision(int key, int (*hash_func)(int), int *hash_table, const char *method) {
if (hash_table[index] != 0) {
printf("Collision detected for key %d at index %d using %s method.\n", key, index, method);
} else {
hash_table[index] = key;
int main() {
int n, key;
scanf("%d", &n);
int keys[n];
key = keys[i];
return 0;
1234 4 2 7
5678 8 9 9
91011 1 1 2
1213 3 7 4
1415 5 2 6
*/
SETB
1.Menu drive
#include <stdio.h>
#include <stdlib.h>
int hashTable[TABLE_SIZE];
void initializeTable() {
hashTable[i] = -1;
// Hash function
return;
hashTable[index] = key;
if (hashTable[index] == key) {
return;
break;
if (hashTable[index] == key) {
hashTable[index] = -1;
return;
if (index == originalIndex) {
break;
}
// Display the hash table
void display() {
printf("Hash Table:\n");
if (hashTable[i] == -1)
else
int main() {
initializeTable();
while (1) {
printf("\nMenu:\n");
scanf("%d", &choice);
switch (choice) {
case 1:
insert(key);
break;
case 2:
scanf("%d", &key);
delete(key);
break;
case 3:
scanf("%d", &key);
search(key);
break;
case 4:
display();
break;
case 5:
exit(0);
default:
return 0;
}
2.Menu drive
#include <stdio.h>
#include <stdlib.h>
int hashTable[TABLE_SIZE];
void initializeTable() {
hashTable[i] = -1;
// Hash function
int i = 1;
i++;
return;
hashTable[index] = key;
int i = 1;
if (hashTable[index] == key) {
return;
}
index = (hashFunction(key) + i * i) % TABLE_SIZE;
i++;
if (i == TABLE_SIZE) {
break;
int i = 1;
if (hashTable[index] == key) {
hashTable[index] = -1;
return;
i++;
if (i == TABLE_SIZE) {
break;
}
}
void display() {
printf("Hash Table:\n");
if (hashTable[i] == -1)
else
int main() {
initializeTable();
while (1) {
printf("\nMenu:\n");
scanf("%d", &choice);
switch (choice) {
case 1:
scanf("%d", &key);
insert(key);
break;
case 2:
scanf("%d", &key);
delete(key);
break;
case 3:
scanf("%d", &key);
search(key);
break;
case 4:
display();
break;
case 5:
exit(0);
default:
}
return 0;