Worksheetshashmap + java-visual
Total questions: 64
Worksheet time: 32mins
Name
Class
Date
1.
Which programming language is used to implement the HashMap in the image?
a)
A: Java [Image shows the text "HashMap in Java" in the image.]
b)
B: C++
c)
C: Python
d)
D: Ruby
2.
The image shows a diagram of a hash table. Which of the following statements is true about the keys in the diagram?
a)
All of the keys have the same hash code.
b)
All of the keys have different hash codes.
c)
Some of the keys have the same hash code, but different key content.
d)
None of the keys have the same hash code.
3.
Which of the following classes in the Java Collections Framework implements the Map interface?
a)
HashMap
b)
ConcurrentSkipListMap
c)
EnumMap
d)
TreeMap
4.
What is the default capacity of the nodes in the image?
a)
8
b)
16
c)
32
d)
64
5.
Which of the following is NOT a bucket?
a)
0
b)
2
c)
3
d)
45
6.
What is the purpose of the listIterator variable in the Java code?
a)
To iterate through the list in both forward and backward directions.
b)
To create a new list iterator object.
c)
To get the next element in the list.
d)
To remove the current element in the list.
7.
How does a HashMap store key-value pairs?
a)
A. It uses a linked list to store each key-value pair.
b)
B. It uses an array to store each key-value pair.
c)
C. It uses a hash table to store each key-value pair.
d)
D. It uses a combination of a hash table and a linked list to store each key-value pair.
8.
Which of the following classes is a concrete implementation of the Map interface?
a)
AbstractMap
b)
HashMap
c)
LinkedHashMap
d)
TreeMap
9.
How are key objects mapped to bucket indexes in a hash table?
a)
A hash function is used to convert the key object into a unique integer value.
b)
The key object is compared to all of the other key objects in the hash table.
c)
The key object is stored in the bucket index that corresponds to its ASCII value.
d)
The key object is stored in the bucket index that corresponds to its hash code.
10.
Which of the following nodes is stored in bucket 3?
a)
A node with key "hello" and value "world"
b)
A node with key "goodbye" and value "bye"
c)
A node with key "world" and value "hello"
d)
A node with key "bye" and value "goodbye"
11.
What is the key value for the value "Seshu"?
a)
9
b)
32
c)
"Deeepak"
d)
55
12.
What is the name of the interface that HashMap implements?
a)
Map
b)
List
c)
Set
d)
Queue
13.
What is the purpose of the image?
a)
To illustrate the internal working of a HashMap in Java.
b)
To show how a HashMap stores key-value pairs.
c)
To explain how a HashMap uses hashCode() and equals() methods.
d)
To demonstrate how a HashMap handles collisions.
14.
What is the purpose of the code in the image?
a)
To create a new HashMap object.
b)
To set the initial capacity of a HashMap object.
c)
To set the load factor of a HashMap object.
d)
To throw an exception if the initial capacity or load factor is invalid.
15.
Which of the following is the best way to iterate over a HashMap in Java?
a)
Iterate through HashMap KeySet using Iterator (This is the code shown in the image.)
b)
Iterate through HashMap EntrySet using Iterator
c)
Iterate through HashMap values() using for-each loop
d)
Iterate through HashMap keys() using for-each loop
16.
What programming language is used in the image?
a)
Java
b)
C
c)
C++
d)
Python
17.
What is the name of the table in the image?
a)
HashMap
b)
Node
c)
Bucket
d)
Threshold
18.
Which of the following students was overwritten by Harry Villalobos in the HashMap?
a)
Silvie Agustin
b)
Antonio Salvatore
c)
Aldrin Dela Cruz
d)
None of the above
19.
What is the internal structure of a HashMap?
a)
A linked list
b)
An array
c)
A hash table
d)
A binary search tree
20.
The diagram shows a HashMap in the Java Collections Framework. Which of the following is the name of the class that implements HashMap?
a)
AbstractMap
b)
SortedMap
c)
HashMap
d)
TreeMap
21.
What is the name of the data structure shown in the image?
a)
Linked List
b)
Stack
c)
Queue
d)
Hash Map
22.
What is the name of the map in the image?
a)
AbstractMap
b)
HashMap
c)
Collection
d)
Map
23.
How many nodes are there in the table of nodes shown in the image?
a)
6
b)
7
c)
8
d)
9
24.
What is the value of the hash field for the entry with the key "latitude.545992"?
a)
-1814782665
b)
545992
c)
null
25.
How many entries are currently in the bucket/table?
a)
1
b)
2
c)
3
d)
4
26.
Which of the following is not a difference between HashMap and ConcurrentHashMap?
a)
HashMap is synchronized internally, while ConcurrentHashMap is not.
b)
HashMap allows null keys, while ConcurrentHashMap does not.
c)
HashMap's iterators are fail-fast, while ConcurrentHashMap's iterators are fail-safe.
d)
HashMap is faster than ConcurrentHashMap.
27.
What is the name of the abstract class that HashMap extends?
a)
AbstractMap
b)
Map
c)
HashMap
d)
Interface
28.
Which of the following is the correct import statement for the Map interface in Java?
a)
import java.util.HashMap;
b)
import java.util.Map;
c)
import java.util.LinkedHashMap;
d)
import java.util.TreeMap;
29.
What is the purpose of the flowchart in the image?
a)
To create a new HashMap object.
b)
To insert a key-value pair into a HashMap object.
c)
To retrieve a value from a HashMap object.
d)
To delete a key-value pair from a HashMap object.
30.
What is the name of the method that is being used to iterate through the hash map in the image?
a)
printMap()
b)
printMapValues()
c)
printMapKeyValues()
d)
printMapEntry()
31.
Which of the following buckets in the image contains the key-value pair 5:Null?
a)
Bucket 0
b)
Bucket 15
c)
Bucket 2
d)
Bucket 3
32.
The image shows an array of linked lists or trees (called buckets/bins). Which of the following data structures is being used?
a)
A. Trees
b)
B. Linked lists
c)
C. Trees and linked lists
d)
D. None of the above
33.
What is the name of the programming language used in the image?
a)
Java
b)
Python
c)
C++
d)
JavaScript
34.
What is the purpose of the hash code bucket in a HashMap?
a)
To store the hash code of the key.
b)
To store the value associated with the key.
c)
To store the index of the bucket in the HashMap.
d)
To store the linked list of elements in the bucket.
35.
Which of the following is the immediate parent class of HashMap in the Java Collections Framework?
a)
AbstractMap
b)
Map
c)
SortedMap
d)
ConcurrentHashMap
36.
What programming language is the code in the image written in?
a)
A. Python
b)
B. C++
c)
C. Java
d)
D. MATLAB
37.
What is the purpose of the yellow sticky note in the image?
a)
To remind the programmer to initialize the hashmap object.
b)
To provide a brief explanation of the unchecked conversion warning.
c)
To list the possible problems that could occur if the hashmap object is not initialized.
d)
To provide a link to the Stack Overflow discussion about this issue.
38.
What is the representation of a node in the image?
a)
Node<K, V>
b)
int hash
c)
Key
d)
Value
39.
How does a HashMap in Java store data?
a)
A. The data is stored in a linked list.
b)
B. The data is stored in a hash table.
c)
C. The data is stored in a binary search tree.
d)
D. The data is stored in a heap.
40.
What is the arrow pointing to in the Java HashMap code?
a)
A. The null key in the HashMap.
b)
B. The Not defined value in the HashMap
c)
C. The map object in the HashMap code.
d)
D. The main() method in the HashMap code.
41.
What is the value of the key Java in the HashMap?
a)
Apache Wickes
b)
Apache Micket
c)
C#.Net
d)
Python-Django
42.
Which of the following is NOT a similarity between ArrayList and HashMap in Java?
a)
Both are backed up by an array.
b)
Both allow duplicate elements.
c)
Both provide constant time lookup performance.
d)
Both are synchronized and thread-safe.
43.
What is the most common type of map in the image?
a)
HashMap
b)
LinkedHashMap
c)
AbstractMap
d)
Serializable
44.
Which of the following is a class that implements the Map interface?
a)
HashMap
b)
AbstractMap
c)
Map
d)
Interface
45.
What is the output of the following code?
a)
John Doe
b)
Default value
c)
An error will be thrown
d)
Correct Answer: 3
46.
Which of the following methods is used to sort a HashMap by values in Java 8?
a)
sorted(Entry.comparingByValue())
b)
stream().sorted(Entry.comparingByValue())
c)
Collectors.toMap(Entry::getKey, Entry::getValue, (e1, e2) -> el, LinkedHashMap::new)
d)
anyMap.entrySet().stream().sorted(Entry.comparingByValue()).collect(Collectors.toMap[Entry::getKey, Entry::getValue, (e1, e2) -> el, LinkedHashMap::new))
47.
The image shows a diagram of a HashMap object in Java. Which of the following is the correct value of the hash field for the key "Naveen"?
a)
1
b)
9
c)
10
d)
16
48.
How many elements are currently stored in the HashMap in the image?
a)
1
b)
3
c)
2
d)
5
49.
Which collision handling strategy is illustrated in the image?
a)
Linear probing
b)
Quadratic probing
c)
Double hashing
d)
Separate chaining
50.
What is the purpose of the code in the image?
a)
A. To create a map of the world.
b)
B. To print a map of the world.
c)
C. To store the capitals of three countries.
d)
D. To print the capital of India.
51.
What is the name of the programming language that is being used in the image?
a)
Java
b)
Python
c)
C++
d)
JavaScript
52.
Based on the image, what is the default capacity of the HashMap?
a)
1
b)
4
c)
8
d)
16
53.
What is the purpose of the code in the image?
a)
To print out a message in the console.
b)
To initialize a static variable.
c)
To create a new object.
d)
To call a method.
54.
What is the name of the key in the image?
a)
int hash
b)
K key
c)
V value
d)
Node<K,V>next
55.
What is the name of the data structure that is used to store the key-value pairs in a HashMap?
a)
A. HashMap
b)
B. Node
c)
C. LinkedList
d)
D. Hashtable
56.
Which bucket in the image contains the entry Entry 1?
a)
Bucket 0
b)
Bucket 1
c)
Bucket 2
d)
Bucket 15
57.
What is the hash code of the key ram in the image?
a)
112671
b)
104075143
c)
156
d)
158
58.
What is the output of the following code?
a)
Apache Wicket
b)
.NET
c)
Django
d)
Travel
59.
What is the return type of the put() method in the image?
a)
Object
b)
K
c)
V
d)
void
60.
What is the purpose of the buckets in the image of a hash map?
a)
To store the key-value pairs in the hash map.
b)
To group together keys that have the same hash code.
c)
To provide a way to quickly look up a key-value pair by its key.
d)
To store the overflow of key-value pairs that do not fit into the buckets.
61.
What is the value of the countries map after the code in the image has been executed?
a)
{Rome=1, Paris=Country("Finland"), Helsinki=3}
b)
{Rome=1, Paris=2, Helsinki=3}
c)
{Rome=1, Paris=Country("Finland"), Helsinki=Country("Finland")}
d)
{Rome=1, Paris=null, Helsinki=3}
62.
Which of the following classes directly extends the Map interface?
a)
HashMap
b)
TreeMap
c)
LinkedHashMap
d)
AbstractMap
63.
What is the purpose of the Map interface in Java?
a)
To store key-value pairs.
b)
To provide a sorted collection of elements.
c)
To provide a way to navigate through a collection of elements.
d)
To implement a hash table.
64.
What is the name of the table in the image?
a)
HashMap
b)
Entry table
c)
Bucket
d)
Node
100 %
