Consider the following C implementation of a hash table:…
Consider the following C implementation of a hash table: #include#define HASH_SIZE 10struct bucket { char* string; struct bucket* next;};typedef struct bucket Bucket;Bucket table[HASH_SIZE];//hash table… unsigned hash(char* key) { unsigned val = 0; while (*key) val = *(key++) + 2 * val; return val % HASH_SIZE;}void init() {//initialize the buckets of my hash table… int i; for (i = 0; i < HASH_SIZE;i++) table[i].string = NULL;}void printHashTable() { int i = 0; Bucket* iterator; for (; i < HASH_SIZE; i++) if (table[i].string) {//not an empty bucket iterator = &table[i];//head of linked list while (iterator) { printf("%s\n", iterator->string); iterator = iterator->next;//advances the iterator… } }}int insert(char* word) { if (search(word)) return 0;//duplicate value, do not add it to the hash table! unsigned index = hash(word); if (table[index].string == NULL) {//empty bucket table[index].string = (char*)malloc(strlen(word) + 1); strcpy(table[index].string, word); table[index].next = NULL; return 1;//successful insert } char* currentHeadOfLinkedList = table[index].next; table[index].next = (Bucket*)malloc(sizeof(Bucket)); table[index].next->string = (char*)malloc(strlen(word) + 1); strcpy(table[index].next->string, word); table[index].next->next = currentHeadOfLinkedList; return 1;}int search(char* word) {//returns 1 if successful and 0 if not int i = hash(word); Bucket* iterator;//link list iterator… if (table[i].string) {//not an empty bucket iterator = table + i;//head of linked list while (iterator) { if (!strcmp(iterator->string, word))//matched return 1; iterator = iterator->next; } } return 0;//unsuccessful search} Also, assume that the following main function uses the hash table to store some strings: main() { int i; init(); char* strings[] = { “AB”, “CD”, “EF”, “GH”, “CD” }; for (i = 0; i < 5;i++) insert(strings[i]); printHashTable();} Answer the following questions: (10 points) Find the hash value of every member of the strings array. The hash value is calculated and returned by the hash function (Hint: ASCII values of letters A, B, C, ... are 65, 66, 67, etc.) (10 points) What's the output of the given C program.
Read DetailsThe conversion of one molecule of pyruvate to three molecule…
The conversion of one molecule of pyruvate to three molecules of CO 2 via pyruvate dehydrogenase and the citric acid cycle also yields _____ molecules of NADH, _____ molecule(s) of FADH 2 , and _____ molecule(s) of ATP (or GTP).
Read DetailsThe standard reduction potentials ( E’ °) for the half rea…
The standard reduction potentials ( E’ °) for the half reactions are given Fumarate + 2H++ 2e– → succinate E’° = +0.031 V FAD + 2H+ + 2e– → FADH2 E’° = –0.219 V If succinate, fumarate, FAD, and FADH2 , all at 1 m concentrations, were mixed together in the presence of succinate dehydrogenase, what would happen initially?
Read DetailsPredict the output of the following C program: #includeun…
Predict the output of the following C program: #includeunion u { struct{ char a, b, c; }s; char string[10];} element;main() { strcpy(element.string, “Hello!”);// copies one string into another element.s.b = ‘i’; element.s.c = ‘?’; printf(“%.3s, %c”, element.string, element.s.a);}
Read Details