CS2114 Test 2
After the following statements execute, what item is at the front of the queue? QueueInterface zooDelivery = new LinkedQueue(); zooDelivery .enqueue("lion"); zooDelivery .enqueue("tiger"); zooDelivery .enqueue("cheetah"); String next = zooDelivery .dequeue(); next = zooDelivery .dequeue(); zooDelivery .enqueue("jaguar");
"cheetah"
In Ch.6, an array- based implementation of a Stack ADT, what value for the topindex of the stack indicates that it is empty?
-1
What is the output of the following program when the method is called with 4? void unknown(int n) { if (n > 0) { System.out.print("?"); unknown(n-1); } }
????
What is the output of the following program when the method is called with 4? void unknown(int n) { if (n > 0) unknown(n-1); System.out.print("?"); }
?????
What is the output of the following program when the method is called with 4? void unknown(int n) { System.out.print("?"); if (n > 0) unknown(n-1); }
?????
Java sorting implementations sort objects that implement the _____ interface.
Comparable
What question should you keep in mind when debugging a recursive method?
Does each base case produce a result that is correct for that case? Are there enough base cases?Is at least one of the cases a base case that has no recursive call?
Imagine you have an empty queue of strings named queue. What is the contents of the queue from front to rear, (listed left to right below), after the following operations have executed: queue.enqueue("K"); queue.enqueue("P"); queue.dequeue(); queue.enqueue("G"); String str = queue.getFront(); queue.enqueue("R"); queue.dequeue(); queue.enqueue("V"); queue.enqueue(str);
GRVP
In a circular array-based implementation of a queue, what is the performance when the dequeue operation ?
O(1)
In a linked chain implementation of a queue, the performance of the enqueue operation is
O(1)
In a linked-based implementation of the ADT list with a tail reference, what is the performance of adding an entry at the end of the list?
O(1)
In the Ch 6 linked-chain implementation of a Stack ADT, the performance of popping an entry from the stack is
O(1)
The efficiency for recursively traversing a chain of linked nodes is
O(n)
The selection sort requires _____ comparisons for an array of n items
O(n^2)
What item is at the front of the list after these statements are executed? DequeInterface waitingLine = new LinkedDeque(); waitingLine.addToFront("Jack"); waitingLine.addToFront("Rudy"); waitingLine.addToBack("Larry"); waitingLine.addToBack("Sam"); String name = waitingLine.getBack();
Rudy
What item is at the front of the list after these statements are executed? DequeInterface waitingLine = new LinkedDeque(); waitingLine.addToFront("Jack"); waitingLine.addToFront("Rudy"); waitingLine.addToBack("Larry"); waitingLine.addToBack("Sam"); String name = waitingLine.getFront();
Rudy
What item is at the front of the list after these statements are executed? DequeInterface waitingLine = new LinkedDeque(); waitingLine.addToFront("Jack"); waitingLine.addToBack("Rudy"); waitingLine.addToBack("Larry"); waitingLine.addToFront("Sam"); String name = waitingLine.getFront(); name = waitingLine.getBack()
Sam
When you declare a method to be protected and final, who can access it?
a subclass
In a chain of linked nodes you can
add nodes from the beginning of a chain, add nodes from the end of a chain, and add nodes that are between other nodes
In the Carrano ListInterface, the method with the signature: public void add(int newPosition, T newEntry); does which of the following
adds a new entry to the specified position in the list, increases the list size by 1, and moves entries originaly at or above the specified position one position higher
Where does a queue add new items?
at the back
You can add a new entry in a list
at the beginning, at the end, and in between items
Where will you find the item added earliest to a queue?
at the front
Recursive methods need a
base case
A superclass is also called a
base class
In the LList implementation of a list, given a node called currentNode, which statement moves the node's reference to the next node?
currentNode = currentNode.getNextNode();
After a call to remove, the nextPosition data field should be
decremented
A subclass is also called a
derived class
When a linked chain contains nodes that reference both the next node and the previous node, it is called a(n)
doubly linked chain
When adding an entry to an array-based implementation of the ADT list at a specified location before the end of the list
entries must be shifted to vacate a position for the new item
What issue should you weigh when considering an implementation for an ADT?
execution time, memory use, and extensibility
To efficiently remove a node at the end of a linked chain implementation of a queue requires a
extra reference in the node pointing to the previous node
To prevent a subclass from overriding protected methods, we declare them to be
final
What type of behavior defines a queue?
first-in first-out
Which method does the interface Iterator specify?
hasNext, next, and remove
How many recursive calls will be made if the following method is called with 6 from main? void greeting(int n) { System.out.println("Hello!"); greeting(n-1); }
infinite
How many recursive calls will be made if the following method is called with 6 from main? void greeting(int n) { if (n > 0) { System.out.println("Hello!"); greeting(n+1); } }
infinite
In an array-based implementation of the ADT list, the makeRoom method does the most work when
newPosition is 1
In the Carrano LList implementation of a list, when a list is empty the firstNode is _____ and the numberOfEntries is _____.
null, 0
In a circular array-based implementation of a queue, the initial size of the array should be
one more than the queue's initial capacity
If you plan for a future subclass to be allowed to manipulate a class's data fields, provide _____ methods to enable the subclass to do this safely and efficiently.
protected
In the Carrano ListInterface, the method with the signature: public T remove(int givenPosition); does which of the following:
removes the entry at a given position from the list
Selecting the smallest element of an array and swapping it with the smallest entry is an operation is which sorting method?
selection sort
Because SortedList is derived from LList, you write_____.add(newPosition, newEntry) to invoke the add operation of the ADT list
super
The node that is easiest to access in a linked-chain is
the head node
In the Ch.6 array based-implementation of a Stack ADT, the entry peek returns may be found at
the last occupied location in the array
In the Ch 6 linked-chain implementation of a Stack ADT, when a node is popped from the stack
the original first node will no longer be referenced, the original first node will be deallocated, and the new first node will reference what was the second node in the chain.
In the linked chain implementation of a queue, the chain's first node contains
the queue's front entry
If iteration has ended, the next method
throws a NoSuchElementException
If the SortedList class inherited the remove by position method from the LList class
we would not have to implement it again