Bird
0
0
DSA Cprogramming~10 mins

Collision Handling Using Open Addressing Linear Probing 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 calculate the hash index for a given key.

DSA C
int hash(int key, int size) {
    return key [1] size;
}
Drag options to blanks, or click blank then click option'
A%
B*
C+
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication (*) instead of modulo (%) causes index out of bounds.
Using addition (+) or subtraction (-) does not limit the index properly.
2fill in blank
medium

Complete the code to find the next index using linear probing.

DSA C
int next_index(int current, int size) {
    return (current [1] 1) % size;
}
Drag options to blanks, or click blank then click option'
A*
B-
C+
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Subtracting 1 causes backward probing which is not standard.
Multiplying or dividing the index is incorrect for linear probing.
3fill in blank
hard

Fix the error in the insertion loop to handle collisions correctly.

DSA C
while (table[index] != -1) {
    index = (index [1] 1) % size;
}
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction causes infinite loops or wrong probing.
Multiplication or division is not suitable for linear probing.
4fill in blank
hard

Fill both blanks to complete the search function using linear probing.

DSA C
int search(int table[], int size, int key) {
    int index = key [1] size;
    int start = index;
    while (table[index] != key) {
        index = (index [2] 1) % size;
        if (index == start) return -1;
    }
    return index;
}
Drag options to blanks, or click blank then click option'
A%
B+
C-
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction for probing causes wrong search path.
Using multiplication or division breaks index calculation.
5fill in blank
hard

Fill both blanks to complete the insertion function with linear probing collision handling.

DSA C
void insert(int table[], int size, int key) {
    int index = key [1] size;
    while (table[index] != -1) {
        index = (index [2] 1) % size;
    }
    table[index] = key;
}
Drag options to blanks, or click blank then click option'
A%
B+
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication in index calculation.
Adding operators when assigning key causes syntax errors.