0
0
Data Structures Theoryknowledge~10 mins

Collision handling (chaining) in Data Structures Theory - Interactive Code Practice

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

Complete the code to initialize an empty hash table with chaining.

Data Structures Theory
hash_table = [[] for _ in [1]]
Drag options to blanks, or click blank then click option'
Alist
B10
Cdict
Drange(10)
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using an integer directly instead of a range.
Using list or dict which are types, not ranges.
2fill in blank
medium

Complete the code to compute the hash index for a key in a hash table of size 10.

Data Structures Theory
index = hash(key) [1] 10
Drag options to blanks, or click blank then click option'
A+
B//
C%
D**
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using division (//) which gives quotient, not remainder.
Using addition (+) which can exceed table size.
3fill in blank
hard

Fix the error in the code that inserts a key-value pair into the hash table using chaining.

Data Structures Theory
hash_table[index].[1]((key, value))
Drag options to blanks, or click blank then click option'
Aadd
Bappend
Cinsert_at
Dput
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using add which is for sets, not lists.
Using non-existent methods like insert_at or put.
4fill in blank
hard

Fill both blanks to complete the code that searches for a key in the hash table using chaining.

Data Structures Theory
for k, v in hash_table[[1]]:
    if k [2] key:
        return v
Drag options to blanks, or click blank then click option'
Aindex
B==
C!=
Dkey
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using the wrong comparison operator like !=.
Using a variable name instead of the index for the bucket.
5fill in blank
hard

Fill all three blanks to complete the code that deletes a key-value pair from the hash table using chaining.

Data Structures Theory
bucket = hash_table[[1]]
for i, (k, v) in enumerate(bucket):
    if k [2] key:
        del bucket[[3]]
        break
Drag options to blanks, or click blank then click option'
Aindex
B==
Ci
Dkey
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using wrong operator like !=.
Deleting by key instead of index.
Using wrong variable names.