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

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:

Map scores; 

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;

scores = new TreeMap;

scores = new Map;

scores = new HashTable;

QUESTION 5

What is the meaning of the type parameter E, in the LinkedList 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:

Stack words1 = new Stack(); 
ArrayList words3 = new ArrayList(); 
words1.push("abc"); 
words1.push("def"); 
words1.push("ghi"); 
while (!words1.empty()) 
{ 
 words3.add(words1.pop()); 
} 
int i = words3.size() - 1; 
while (i >= 0) 
{ 
 System.out.print(words3.remove(i)); 
 i--; 
} 

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:

Queue stringQueue = new LinkedList(); 
stringQueue.add("ab"); 
stringQueue.add("abc"); 
stringQueue.add("a"); 
while (stringQueue.size() > 0) 
{ 
 System.out.print(stringQueue.remove() + ","); 
} 

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.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!