Question 21
EasyWhat is the output of this code?
s = set([1, 2, 2, 3, 3, 3])
print(len(s))
- A.
3
- B.
2
- C.
1
- D.
6
Sign up free to see the answer and a step-by-step explanation.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
What is the output of this code?
s = set([1, 2, 2, 3, 3, 3])
print(len(s))
3
2
1
6
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
d = {}
for w in ['x', 'y', 'x']:
d[w] = d.get(w, 0) + 1
print(d['x'])
0
3
1
2
Sign up free to see the answer and a step-by-step explanation.
Is the iteration order of keys guaranteed in a Java HashMap?
Yes, always insertion order
Yes, always sorted
No
Yes, reverse order
Sign up free to see the answer and a step-by-step explanation.
In hashing, what is rehashing?
Deleting all keys
Sorting the keys
Building a bigger table and inserting every key into it again
Hashing a key twice for safety
Sign up free to see the answer and a step-by-step explanation.
What is a perfect hash function?
One that never changes the key
One that is very short
One that causes no collisions for a known, fixed set of keys
One that returns random numbers
Sign up free to see the answer and a step-by-step explanation.
Why are hash tables a poor choice for range queries such as 'all keys between 10 and 20'?
Keys are scattered by the hash function, not stored in order
Hash tables cannot store numbers
Hash tables are always full
Range queries need recursion
Sign up free to see the answer and a step-by-step explanation.
A hash table has 40 slots holding 30 keys. What is its load factor?
10
0.75
1.33
30
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
nums, target = [2, 7, 11, 15], 9
seen = {}
ans = None
for i, x in enumerate(nums):
if target - x in seen:
ans = (seen[target - x], i)
break
seen[x] = i
print(ans)
(0, 2)
(1, 2)
(0, 1)
None
Sign up free to see the answer and a step-by-step explanation.
Keys 12, 22, 32 are inserted into a hash table of size 10 with h(k) = k mod 10 and linear probing. Where does 32 go?
Index 4
Index 2
Index 3
Index 5
Sign up free to see the answer and a step-by-step explanation.
What is clustering in linear probing?
Hashing to a negative index
Keys being stored in a tree
The table becoming empty
Long runs of occupied slots form, making further insertions and searches slower
Sign up free to see the answer and a step-by-step explanation.