Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a hash table array of size 10.
DSA C
int hashTable[[1]]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero size array which is invalid.
Choosing a size too small like 0 or 1.
✗ Incorrect
The hash table size is commonly set to 10 here for simplicity.
2fill in blank
mediumComplete the hash function to compute index using modulo operator.
DSA C
int hashFunction(int key) {
return key [1] 10;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition or multiplication instead of modulo.
Returning key directly without limiting index range.
✗ Incorrect
Modulo operator (%) returns remainder, used to keep index within table size.
3fill in blank
hardFix the error in the insertion function to store value at correct index.
DSA C
void insert(int key, int value) {
int index = hashFunction(key);
hashTable[[1]] = value;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using key as index which may be out of bounds.
Using value or hashTable as index which is incorrect.
✗ Incorrect
We must use the computed index to store the value in the hash table.
4fill in blank
hardFill both blanks to complete the search function returning value or -1 if not found.
DSA C
int search(int key) {
int index = hashFunction(key);
if (hashTable[[1]] != [2]) {
return hashTable[index];
}
return -1;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with key instead of empty value.
Using wrong index or wrong empty value.
✗ Incorrect
Check if the slot at 'index' is not empty (0 means empty here).
5fill in blank
hardFill all three blanks to complete a hash function using multiplication and modulo.
DSA C
int hashFunction(int key) {
int hash = (key [1] 31) [2] 10;
return hash [3] 0 ? hash : -hash;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of multiplication.
Using wrong comparison operator.
Not handling negative hash values.
✗ Incorrect
Multiply key by 31, modulo 10, then check if hash is positive.
