QUESTION 1 Complete the following code snippet, which is intended to determine i
ID: 3830171 • Letter: Q
Question
QUESTION 1
Complete the following code snippet, which is intended to determine if a specific value in a variable named targetWord appears in a set of Stringvalues named mySet:
if (mySet.equalsIgnoreCase(targetWord))
if (mySet == targetWord)
if (mySet.contains(targetWord))
if (mySet.get(targetWord))
1 points
QUESTION 2
Suppose we create a deque (double-ended queue) data structure. It is basically a queue, with its addLast and removeFirst operations, but we also add the addFirst and removeLast operations. Which of the following is best modeled by the deque data structure?
A toll booth on a highway.
A cross country race.
A computer keyboard typing buffer.
A Memorial Day parade.
1 points
QUESTION 3
Print jobs submitted to a printer would probably be stored in which type of data structure?
queue
linked list
stack
hash table
1 points
QUESTION 4
When using a list iterator, on which condition will the IllegalStateException be thrown?
Calling remove after calling next.
Calling next after calling previous.
Calling remove after calling remove.
Calling remove after calling previous.
1 points
QUESTION 5
Rather than storing values in an array, a linked list uses a sequence of ____.
indexes
nodes
elements
accessors
1 points
QUESTION 6
Which of the following statements about data structures is correct?
Inserting and removing elements that have already been located is faster with a list than with a set.
Accessing elements in a linked list in a random fashion is efficient.
Adding and removing already-located elements in the middle of a linked list is efficient.
A set is an ordered collection of unique elements.
1 points
QUESTION 7
You need to access values in objects by a key that is not part of the object. Which collection type should you use?
Map
Hashtable
ArrayList
Queue
1 points
QUESTION 8
Consider the code snippet shown below:
What will be printed when this code is executed?
abcdefghi
ghiabcdef
abcghidef
defghiabc
1 points
QUESTION 9
Which of the following statements about manipulating objects in a set is correct?
If you try to add an element that already exists, an exception will occur.
A set iterator visits elements in the order in which they were added to the set.
You can add an element at the position indicated by an iterator.
You can remove an element at the position indicated by an iterator.
1 points
QUESTION 10
You use a(n) ____ to access elements inside a linked list.
accessor
index
list iterator
queue
1 points
QUESTION 11
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,
1 points
QUESTION 12
You need to write a program to simulate the effect of adding an additional cashier in a supermarket to reduce the length of time customers must wait to check out. Which data structure would be most appropriate to simulate the waiting customers?
map
stack
queue
linked list
1 points
QUESTION 13
Suppose we have two String objects and treat the characters in each string from beginning to end in the following way: With one string, we push each character on a stack. With the other string, we add each character to a queue. After processing both strings, we then pop one character from the stack and remove one character from the queue, and compare the pair of characters to each other. We do this until the stack and the queue are both empty. What does it mean if all the character pairs match?
The strings are the identical.
The strings are different.
One string is the reverse of the other.
We can only conclude the strings are of the same length
1 points
QUESTION 14
Assume that you have declared a map named myMap to hold String elements with Integer keys. Which of the following statements will correctly insert an element into myMap?
myMap.insert(3, "apple");
myMap.put(3, "apple");
myMap.push(3, "apple");
myMap.add(3, "apple");
1 points
QUESTION 15
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
1 points
QUESTION 16
Which data structure would best be used for finding a path out of a maze?
queue
stack
list
array
1 points
QUESTION 17
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.
1 points
QUESTION 18
Which Java package contains the LinkedList class?
java.lang
java.util
java.collections
java.io
1 points
QUESTION 19
Assume that you have declared a stack named myStack to hold String elements. Which of the following statements will correctly remove an element from myStack?
myStack.remove();
myStack.get();
myStack.delete();
myStack.pop();
1 points
QUESTION 20
Suppose you push integer elements 1,2,3,4 onto a stack in that order. Then pop an element off the stack and add that element to a queue. You repeat that process three more times. In what order will you remove the elements from the queue?
1,2,3,4
1,2,4,3
4,3,2,1
4,3,1,2
if (mySet.equalsIgnoreCase(targetWord))
if (mySet == targetWord)
if (mySet.contains(targetWord))
if (mySet.get(targetWord))
Explanation / Answer
Hi, I have answered first 5 qustions. Please repost others in separate post.
1)
for (String aWord : mySet)
{
if (mySet.contains(targetWord))
{
System.out.println ("The word " + targetWord + " was found.");
}
)
3)
queue
4)
Calling remove after calling remove
5)
nodes
6)
Inserting and removing elements that have already been located is faster with a list than with a set.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.