
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define capacity 101 // Size of Hash Table
int hash_function(char* str) {
int i = 0;
for (int j=0; str[j]; j++)
i += str[j];
return i % capacity;
}
struct Ht_item {
char* name;
int numberCourses;
};
// Hash Table Definition
struct HashTable {
struct Ht_item** items;
int size;
int count;
};
struct Ht_item* create_item(char* key, int value) {
struct Ht_item* item = (struct Ht_item*) malloc (sizeof(struct Ht_item));
item->name = (char*) malloc (strlen(key) + 1);
item->numberCourses = value;
strcpy(item->name, key);
item->numberCourses = value;
return item;
}
struct HashTable* create_table(int size) {
// Creates a New Hash Table
struct HashTable* table = (struct HashTable*) malloc (sizeof(struct HashTable));
table->size = size;
table->count = 0;
table->items = (struct Ht_item**) calloc (table->size, sizeof(struct Ht_item*));
for (int i=0; i<table->size; i++)
table->items[i] = 0;
return table;
}
void put(struct HashTable* table, char* key, int value) {
struct Ht_item* item = create_item(key, value);
int index = hash_function(key);
struct Ht_item* current_item = table->items[index];
if (current_item == 0) {
// Key Not Available
if (table->count == table->size) {
// Hash Table Full
printf("Hash Table Full...\n");
return;
}
// Direct Insertion
table->items[index] = item;
table->count++;
}
else {
if (strcmp(current_item->name, key) == 0) {
table->items[index]->numberCourses = value;
return;
}
else {
// Write the collision case using loop?
}
}
}
int contains(struct HashTable* table, char* key) {
// Search in Hash Table
// Return 0 if Not Available
int index = hash_function(key);
struct Ht_item* item = table->items[index];
if (item != 0) {
if (strcmp(item->name, key) == 0)
return item->numberCourses;
}
return 0;
}
int get(struct HashTable* table, char* key){
}
void display(struct HashTable* table, char* key) {
int val;
if ((val = contains(table, key)) == 0) {
printf("Key: %s Not Available...\n", key);
return;
}
else {
printf("Key: %s, Value: %d\n", key, val);
}
}
int main() {
struct HashTable* ht = create_table(capacity);
put(ht, "Alex", 4);
put(ht, "Amy", 3);
put(ht, "Tiny", 7);
put(ht, "Amy", 2);
put(ht, "Cary", 3);
display(ht, "Mark");
display(ht, "Amy");
display(ht, "Tiny");
display(ht, "Cary");
display(ht, "Alex");
return 0;
}
The code for the problem is given above.
// Write the collision case using loop? (handle the collision case in the comment section and it will search linearly.)
The get function itself gives the number of lessons learned for the most sent key. send it. If the key is not present in the map, it returns -1. (Write the get function in accordance with the definition.)
Complete the code by adding the specified problems to the code.

Step by stepSolved in 2 steps

- You can create an empty dictionary with dictionary() [ ] ( ) { } This data structure stores a collection of objects in an unordered manner where each object must be unique dictionary set tuple listarrow_forwardQuestion 44 Computer Science A list of elements has a size of 100. Choose the operations where an ArrayList would be faster than a LinkedList. (Select all that apply) Question 5 options: removing from index 99 inserting at index 1 removing from index 4 inserting at index 4 Full explain this question and text typing work onlyarrow_forwardData Structure & Algorithm: Describe and show by fully java coded example how a hash table works. You should test this with various array sizes and run it several times and record the execution times. At least four array sizes are recommended. 10, 15, 20, 25. It is recommended you write the classes and then demonstrate/test them using another classarrow_forward
- Data Structures/Algorithms in Javaarrow_forward2) Hash Innards Homework • Unanswered Select all true statements from the below. Multiple answers: Multiple answers are accepted for this question Select one or more answers and submit. For keyboard navigation. SHOW MORE V a A hash function takes a key and produces an index into the hash table. The next step in this process is often something like 'h%SIZE' so that the hash value of the key will fit within the table b (having SIZE elements, you see). Common techniques involve exclusive or of bits within the key and folding different sections of bits within the key into each other. The best hash method for character strings is to simply add up the ASCIlI values of their individual characters. Coming up with a perfect hash for a given set of keys can be a difficult and time-consuming task.arrow_forwardIn C++.arrow_forward
- 2 = 0 ) { numList [ i ] i } } } [1, 2, 3, 4, 5] [0, 2, 4, 6, 8] [2, 4, 6, 8, 10] [1, 3, 5, 7, 9]arrow_forwardC++ Hello im trying to make a list for my code but i cant use the <list> library, how would i make a list for my linked list array based hashtable code wordlist: incase you want to test the entire code a aaa hello goodbye #pragma once //hashtable.h #include <iostream> #include <string> #include <list> #include <cstdlib> #include "word.h" using namespace std; class HashTable { int BUCKET; list<Word>* table; public: HashTable(int W); //to check if the table is empty bool isEmpty() const; //to insert a key into the hashtable void insertItem(string& x); //to delete a key from the hashtable void deleteItem(int key); int hashFunction(Word x); //to look for the key in the table bool searchTable(string& key); void displayHash(); }; //hashtable.cpp #include "hashtable.h" #include <iostream> HashTable::HashTable(int W) { table = new list < Word >[W]; BUCKET = W; return; } //to check if the table is empty bool…arrow_forwardStudent* func () { unique ptr arr[] make_unique ("CSC340") }; // #1 Insert Code int main () ( // #2 Insert Code [ #1 Insert Code]: Write code to keep all the object(s) which element(s) of array arr owns alive outside of the scope of func. [#2 Insert Code]: Write code to have a weak_ptr monitor the object which survived; Then test if it has any owner; Then properly destroy it; Then test again if has any owner; Then destroy the Control Block.arrow_forward
- //client.c#include "csapp.h" int main(int argc, char **argv){ int connfd; rio_t rio; connfd = Open_clientfd(argv[1], argv[2]); Rio_readinitb(&rio, connfd); char buffer[MAXLINE]; printf("Your balance is %s\n", buffer); Close(connfd); exit(0); int choice; float amount; int acc2; char buffer[MAXLINE]; rio_t rio; Rio_readinitb(&rio, connfd); while (1) { printf("\nHello welcome to the Bank Management System\n"); printf("----------------------\n"); printf("1. Check Balance\n"); printf("2. Deposit\n"); printf("3. Withdraw\n"); printf("4. Transfer\n"); printf("5. Quit\n"); printf("Enter your choice: "); Rio_writen(connfd, &choice, sizeof(int)); if (choice == 1) { printf("Your balance is %s\n", buffer); } else if (choice == 2) { printf("Enter amount to deposit: "); Rio_writen(connfd, &amount,…arrow_forwardfast please c++ Insert the elements of A in hash table H of size 10. H is a vector of int is size 10. Do not allow duplicates. Draw the table. The hash function is the number itself; f(n) = n%10arrow_forward1. Goals and Overview The goal of this assignment is to practice creating a hash table. This assignment also has an alternative, described in Section 5. A hash table stores values into a table (meaning an array) at a position determined by a hash function. 2. Hash Function and Values Every Java object has a method int hashCode() which returns an int suitable for use in a hash table. Most classes use the hashCode method they inherit from object, but classes such as string define their own hashCode method, overriding the one in object. For this assignments, your hash table stores values of type public class HashKeyValue { K key; V value; } 3. Hash Table using Chained Hashing Create a hash table class (called HashTable211.java) satisfying the following interface: public interface HashInterface { void add(K key, V value); // always succeeds as long as there is enough memory V find (K key); // returns null if there is no such key } Internally, your hash table is defined as a private…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





