Bird
0
0
DSA Cprogramming~10 mins

Collision Handling Using Chaining 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 initialize the head of the linked list to NULL in the hash table.

DSA C
hashTable->buckets[index].head = [1];
Drag options to blanks, or click blank then click option'
ANULL
Bhead
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of NULL which is less clear.
Assigning 1 or an uninitialized variable.
2fill in blank
medium

Complete the code to create a new node and assign the key value in the chaining linked list.

DSA C
newNode = (Node*)malloc(sizeof(Node));
newNode->key = [1];
Drag options to blanks, or click blank then click option'
ANULL
Bkey
Cindex
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning value or index instead of key.
Assigning NULL which is invalid for key.
3fill in blank
hard

Fix the error in the code to insert the new node at the beginning of the linked list for chaining.

DSA C
newNode->next = [1];
hashTable->buckets[index].head = newNode;
Drag options to blanks, or click blank then click option'
AhashTable->buckets[index].head
BnewNode
CNULL
Dhead
Attempts:
3 left
💡 Hint
Common Mistakes
Setting next to newNode causes a cycle.
Setting next to NULL loses the existing list.
4fill in blank
hard

Fill both blanks to complete the search function that traverses the linked list to find a key.

DSA C
Node* current = hashTable->buckets[index].head;
while (current != [1]) {
    if (current->key == [2]) {
        return current;
    }
    current = current->next;
}
Drag options to blanks, or click blank then click option'
ANULL
Bkey
C0
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of NULL to check end of list.
Comparing with index instead of key.
5fill in blank
hard

Fill all three blanks to complete the delete function that removes a node with a given key from the chain.

DSA C
Node* current = hashTable->buckets[index].head;
Node* prev = [1];
while (current != NULL && current->key != [2]) {
    prev = current;
    current = current->next;
}
if (current == NULL) return;
if (prev == NULL) {
    hashTable->buckets[index].head = current->next;
} else {
    prev->next = [3];
}
free(current);
Drag options to blanks, or click blank then click option'
ANULL
Bkey
Ccurrent->next
DhashTable->buckets[index].head
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing prev to head instead of NULL.
Comparing with index instead of key.
Setting prev->next to current instead of current->next.