0
0
DSA Pythonprogramming~10 mins

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

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

Complete the code to create an empty hash table using a dictionary.

DSA Python
hash_table = [1]
Drag options to blanks, or click blank then click option'
A{}
B[]
C()
Dset()
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets creates a list, not a dictionary.
Using parentheses creates a tuple, which is not a hash table.
2fill in blank
medium

Complete the code to add a key-value pair to the hash table.

DSA Python
hash_table['apple'] = [1]
Drag options to blanks, or click blank then click option'
A1
BTrue
C'fruit'
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number instead of a descriptive string.
Using None which means no value.
3fill in blank
hard

Fix the error in the hash function to return a valid index.

DSA Python
def hash_function(key, size):
    return sum(ord(char) for char in 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 or addition changes the value incorrectly.
Using floor division (//) does not keep the index within range.
4fill in blank
hard

Fill both blanks to create a hash table with keys from a list and values as their lengths.

DSA Python
hash_table = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as value instead of its length.
Using less than (<) instead of greater than (>) in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys, values as word lengths, and filter words longer than 4.

DSA Python
result = [1]: [2] for word in words if len(word) [3] 4}
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
C>
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase keys instead of uppercase.
Using less than (<) instead of greater than (>) in the condition.
Using the word itself as value instead of its length.