QUESTION 1 Which of the following algorithms would be efficiently executed on an
ID: 3806414 • Letter: Q
Question
QUESTION 1
Which of the following algorithms would be efficiently executed on an ArrayList?
add 1 element to the middle of a list with n elements
add n / 2 elements to a list with n / 2 elements
remove first n / 2 elements from a list of n elements
read n / 2 elements in random order from a list of n elements
QUESTION 2
Which of the following statements about linked lists is correct?
Once you have located the correct position, adding elements in the middle of a linked list is inefficient.
Visiting the elements of a linked list in random order is efficient.
When a node is removed, all nodes after the removed node must be moved down.
Linked lists should be used when you know the correct position and need to insert and remove elements efficiently.
QUESTION 3
You need to access values by an integer position. Which collection type should you use?
Map
Hashtable
ArrayList
Queue
QUESTION 4
Consider the following code snippet:
If you need to visit the keys in sorted order, which of the following statements will create a structure to support this?
scores = new HashMap<String, Integer>;
scores = new TreeMap<String, Integer>;
scores = new Map<String, Integer>;
scores = new HashTable<String, Integer>;
QUESTION 5
What is the meaning of the type parameter E, in the LinkedList<E> code fragment?
The elements of the linked list are of class E.
The elements of the linked list are of any subclass of class E.
The elements of the linked list are any type supplied to the constructor.
The elements of the linked list are of class Object.
QUESTION 6
Consider the following code snippet:
What will this code print when it is executed?
abcdefghi
ghiabcdef
abcghidef
defghiabc
QUESTION 7
You intend to use a hash set with your own object class. Which of the following statements is NOT correct?
You do not have to do anything additional. You can use the hashCode function of the Object class.
You can create your own function to compute a hashCode value.
You can override the hashCode method in the Object class to provide your own hashCode method.
Your class's hashCode method does not need to be compatible with its equals method.
QUESTION 8
Consider the following code snippet:
What output will be produced when this code is executed?
ab,abc,a,
a,abc,ab,
a,ab,abc,
abc,ab,a,
QUESTION 9
A collection that allows speedy insertion and removal of already-located elements in the middle of it is called a ____.
linked list
stack
set
queue
QUESTION 10
The ArrayList class implements the ____.
Queue interface.
Set interface.
List interface.
Stack interface.
add 1 element to the middle of a list with n elements
add n / 2 elements to a list with n / 2 elements
remove first n / 2 elements from a list of n elements
read n / 2 elements in random order from a list of n elements
Explanation / Answer
1) Option D
2) Option A
3) Option C
4) Option B
5) Option D
6) Option A
7) Not Sure
8) Option A
9) Option A
10) Option C
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.