Bird
0
0
DSA Cprogramming~10 mins

Hash Table Concept and Hash Functions in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A10
B5
C0
D100
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero size array which is invalid.
Choosing a size too small like 0 or 1.
2fill in blank
medium

Complete 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'
A*
B%
C-
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition or multiplication instead of modulo.
Returning key directly without limiting index range.
3fill in blank
hard

Fix 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'
Akey
Bvalue
ChashTable
Dindex
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.
4fill in blank
hard

Fill 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'
Aindex
Bkey
C0
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with key instead of empty value.
Using wrong index or wrong empty value.
5fill in blank
hard

Fill 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'
A*
B%
C>
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of multiplication.
Using wrong comparison operator.
Not handling negative hash values.