A Node class for a linked list that can hold elements of type Object can be decl
ID: 3838454 • Letter: A
Question
A Node class for a linked list that can hold elements of type Object can be declared to have fields
Question 2 options:
Object element; Node next;
Object element; next element;
Object element;
Object element; Node *next;
Save
Question 3
In a linked list, the predecessor of a node X
Question 3 options:
is the node that comes after X
is undefined if X is the first node, otherwise it is the node whose index is one less than the index of X
is the first node in the list
is the node that is just before X
Save
Question 4
A list method E remove(int index) designed to remove and return the element at the given index should throwIndexOutOfBoundsException when
Question 4 options:
the index is 0
the index is negative, or is greater than, or equal to, the size of the list
the index is negative, and greater than the size of the list
the index is negative, or is greater than the size of the list
Save
Question 5
A doubly linked list makes it easy to
Question 5 options:
to create a second copy of the linked list
skip two nodes at a time when moving backward through the list
skip two nodes at a time when moving forward through the list
move from any node to its successor, and from any node to its predecessor
Save
Question 6
The stack push operation
Question 6 options:
removes and returns an item from the stack
returns the item at the top of the stack, but does not remove it
adds a single item to the stack
is normally implemented through a hash set
Save
Question 7
The stack peek operation
Question 7 options:
checks a stack to see if there are any elements in it
returns the item at the top of the stack, but does not remove it
removes and returns an item from the stack
adds a single item to the stack
Save
Question 8
The stack empty operation
Question 8 options:
checks to see if there is at least one item on the stack
destroys the stack and creates a new empty one in its place
removes all elements from the stack
None of the above
Save
Question 9
The stack pop operation
Question 9 options:
removes from the stack the number of elements specified by its integer parameter
removes all items currently on the stack
extracts one element from the stack and returns it
does not exist: There is no such stack operation
Save
Question 10
Consider a class that uses the following variables to implement an array-based stack:
String [ ] s = new String[100];
int top = 0;
The boolean method to check for an empty stack can be written as:
Question 10 options:
if (s == null)
return true;
else
return false;
if (s.length == 0)
return true;
else
return false;
return top;
if (top == 0)
return true;
else
return false;
Save
The operation for removing an item from a queue is called
Question 11 options:
disqueue
enqueue
dequeue
extract
Save
A queue based on a linked list uses the following code
class Node{
String element;
Node next;
Node (String el, Node n)
{
element = el;
next = n;
}
}
Node front = null, rear = null;
What is the right code for String remove() operation? Such an operation removes and returns an element from the queue.
Question 12 options:
if (front == null)
throw new RuntimeException("Empty");
String temp = front.element;
front = front.next;
if (front == null)
front = rear;
return temp;
if (rear== null)
throw new RuntimeException("Empty");
String temp = rear.element;
rear = rear.next;
if (front == null)
rear = null;
return temp;
if (front == null)
throw new RuntimeException("Empty");
String temp = front.element;
front = front.next;
if (front == null)
rear = null;
return temp;
if (front == rear)
throw new RuntimeException("Empty");
String temp = front.element;
front = front.next;
if (front == null)
rear = null;
return temp;
Save
The predecessor of a node in a binary tree is called its
Question 13 options:
precursor
progenitor
ancestor
parent
Save
In a binary tree,
Question 14 options:
there must be exactly one node with no predecessor
there may be at most two nodes with no predecessor
there must be at most one node with no predecessor
there may be any number of nodes with no predecessor
Save
Question 15
The successor of a node in a binary tree is called its
Question 15 options:
neighbor
descendant
neighbor
child
Save
An empty binary tree has height
Question 16 options:
-1
1
0
None of the above: the height of an empty binary tree is not defined.
Save
Question 17
An AVL tree is
Question 17 options:
a priority queue with a balance condition
a binary search tree in which the heights of the subtrees at each node differ by at most one
a binary tree in which the left and right subtree have heights that differ by at most one
a binary tree in which each child is greater than its parent
Save
Question 18
A priority queue is
Question 18 options:
a binary search tree in which the heights of the subtrees at each node differ by at most one
is an AVL tree in which the root is the minimum element
is a collection that allows elements to be added, but only allows the minimum element to be removed
is a binary search tree that stores elements according to their natural order
Save
Question 19
A complete binary tree with N nodes has depth approximately equal to
Question 19 options:
log N
2N
N
N2
Save
Question 20
The concrete classes that implement the List interface are
Question 20 options:
AbstractList, AbstractSequentialList, and List
LinkedList, ArrayList, and Vector
LinkedList, ArrayList, and AbstractList
None of the above
Save
Question 21
Comparator
Question 21 options:
specifies two methods, compare and equals
specifies two methods, compare and compareTo
specifies a single method, compareTo
specifies three methods, compareTo, compare, and equals
Save
Question 22
A TreeSet
Question 22 options:
is like a Set that allows elements to be retrieved according to their natural order, or according to an order specified by aComparator
is a Set that allows elements to be retrieved in the order added
is like a Set, only it is faster
is a Set that organizes its elements in a tree according to the inheritance hierarchy of the elements
Save
Question 23
A HashMap
Question 23 options:
uses hash codes to store keys
is a subclass of HashSet that implements the Map interface
is a subclass of Map that implements the HashCode interface
None of the above
Save
Question 24
A LinkedHashMap
Question 24 options:
provides an iterator that can be used to retrieve its elements
is an unordered collection that provides no control over the order of retrieval of stored elements
can be set up to maintain its keys in insert or access order
None of the above
Save
Question 25
Collections
Question 25 options:
is a class that contains static methods for working with collections
is the interface from which all collection interfaces are derived
is the superclass of all abstract and concrete collection classes
None of the above
Object element; Node next;
Object element; next element;
Object element;
Object element; Node *next;
Explanation / Answer
Solution:
2. Object element; Node *next;
3. is undefined if X is the first node, otherwise it is the node whose index is one less than the index of X
4. the index is negative, or is greater than, or equal to, the size of the list
5. move from any node to its successor, and from any node to its predecessor
6. adds a single item to the stack
7. returns the item at the top of the stack, but does not remove it
8. checks to see if there is at least one item on the stack
9. extracts one element from the stack and returns it
10. if (s.length == 0)
return true;
else
return false;
11. Dequeue
12. if (front == null)
throw new RuntimeException("Empty");
String temp = front.element;
front = front.next;
if (front == null)
front = rear;
return temp;
13. Ancestor
14. there must be exactly one node with no predecessor
15. Descendant
16. -1
17. a binary search tree in which the heights of the subtrees at each node differ by at most one
18. is a collection that allows elements to be added, but only allows the minimum element to be removed
19. log N
20. LinkedList, ArrayList, and Vector
21. specifies two methods, compare and equals
22. is like a Set that allows elements to be retrieved according to their natural order, or according to an order specified by aComparator
23. is a subclass of HashSet that implements the Map interface
24. provides an iterator that can be used to retrieve its elements
25. is the interface from which all collection interfaces are derived
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.