Ch 9: Stacks & Queues for Data Structures_DNS_Copy
What will the list look like if the following code is run: myList.addNodeToHead(75); myList.addNodeToTail(100); myList.addNodeToHead(50);
50, 75, 100
Which of the following is a practical example of a doubly linked list? 1. A browser cookie file. 2. A first-in-first out scheduling system. 3. A quest in a game that lets users retry stages. 4. A game in which the player runs forward.
A quest in a game that lets users retry stages. A quest in a game that lets users retry stages. A quest in a game that lets users retry stages. A quest in a game that lets users retry stages. A quest in a game that lets users retry stages.
Which two methods add an element to the back of the queue? 1. add, append 2. add, insert 3. add, inject 4. add, offer
Add,offer. Add,offer. Add,offer. Add,offer. Add,offer.
What could you change to make the following code not result in a error?
Change ''implements C'' to ''implements A''
Which type of queue can be sued as a queue or stack?
Double-ended queue
When an item is removed from a linked list, what happens to the other element references?
Element indexes are re-ordered.
Which construct is used by regular queues?
First-in,first-out
What keyword is used when creating a class that uses an interface?
Implements
Which Java language construct is commonly used to create abstract data types?
Interfaces
When you add an ew element to the tail of a circularly linked list, what is true of the current tail?
It connect to the head
The following linked list, called j, exists in your program: [J, U, P, I, T, E, R] If you execute the following code, what will be the final value? j.add(2, "CERES");
J, U, CERES, P, I, T, E, R]
Stack operation is based on what approach\?
LIFO
Stack operation is based on what approach? 1. LOFI 2. LIFO 3. FIFO 4. FOLI
LIFO last-in-first-out. LIFO last-in-first-out. LIFO last-in-first-out.
What is the purpose of the following Java code in context of a doubly-linked list? Node myNode = new Node(element); Node end = head; while(end.next != null) { // Perform some operation or update on the current node System.out.println(end.data); // Example: Print the data of the current node // Move to the next node end = end.next; } 1. This code will result in an error. 2. Looping to find the first node of the list. 3. Looping until the last node is found. 4. Rotating the head and the tail.
Looping until the last node is found. Looping until the last node is found. Looping until the last node is found. Looping until the last node is found. Looping until the last node is found.
If you need to remove an element from the tail of a circular linked list, what special step is needed?
Make sure the tail is really the last item
Which of the following correctly checks to see if the current node is the head of a doubly linked list? a. Node myNode = new Node(element); if(myNode.next == tail) { } b. Node myNode = new Node(element); if(myNode.prev == null) { } c. Node myNode = new Node(element); if(myNode.next == null) { } d. Node myNode = new Node(element); if(myNode == null) { }
Node myNode = new Node(element); if(myNode.prev == null) { }
Why would an enhanced for loop not work with a circular lined list?
Nodes are all connected, it would result in infinite loop
When creating a stack data type in Java, which method are most appropriate for the interface to the Stack? 1. Push, pop, peek, size, isEmpty 2. Push, poke, peek, size, isEmpty 3. isEmpty, pop, size 4. Push, peek, size, isEmpty
Push, pop, peek, size, isEmpy
Which statement is true?
Regular queues use the first-in, first-out structure while priority queues remove elements based on priory
What does the remove method do in regard to priority queues?
Remove the highest priority element in the queue
What is the function of the following code? tail = head; head = head.next;
Rotating the list
Which implementation method provides the best efficiency?
Sorted list
When would it be most appropriate to create a linked list in Java?
Storing elements in a dynamic array.
Which is true about an interface definition?
The methods have no bodies
When using a linked list to represent a stacks, which element(s) do you have access to within the stack? 1. All nodes before the top (tail) 2. All nodes in the stack 3. The bottom (head) 4. The top (tail)
The top (tail). The top (tail). The top (tail). The top (tail).
What does it mean for a data type to be abstract?
The ways its behaviors are implemented are not defined.
Which of the following statements is true about an unsorted list?
Unsorted lists have no organized order
What method is used to populate priority queue?
add
All of the following are associated with queue in Java EXCEPT: 1. interface methods 2. abstract 3. directly defined 4. first-in first-out
directly defined. directly defined. directly defined. directly defined. directly defined. directly defined. directly defined. directly defined. directly defined. directly defined. directly defined. directly defined.
Which of the following Java code snippets correctly starts at the end of a Node called m? 1. if(m.prev == null) 2. while(m.end == null) 3. while(m != null) 4. if(m.next == null)
if(m.next == null). if(m.next == null). if(m.next == null).
Which of the following correctly appends a new value specifically to the tail of the following linked list: LinkedList l = new LinkedList(); l.add("M"); l.add("A"); l.add("R");
l.addLast("S");
Which construct is used by stacks?
last-in, first-out
In the following linked list (named m in your code), you need to change the Z to an S. Which code example accomplishes this? [M, A, R, Z];
m.set(3, "S");
If you had a Java class called myDll, how would you create a new doubly linked list instance? 1. this.node = new myDll(); 2. new Node = myDll 3. myDll dll = new myDll(); 4. myDll = new Node();
myDll dll = new myDll(); myDll dll = new myDll();
Which of the following Java statements is correct with a queue name of 'myQueue' and the data of type integer? 1. add(myQueue, 319); 2. add(myQueue.319); 3. myQueue.add(319); 4. myQueue.add('319');
myQueue.add(319); myQueue.add(319); myQueue.add(319);
Which method retrieves bit does not remove the element at the head of the deque?
peek The peek retrieves the head item but does not remove it.
Which Queue interface method retrieves the front element of a queue without removing it? 1. poll 2. peek 3. look 4. offer
peek. peek. peek. peek. peek. peek. peek. peek.
Which Queue Interface method retrieves and removes the front element of a queue? 1. look 2. offer 3. peek 4. poll
poll. poll. poll. poll. poll. poll. poll. poll. poll.
Which method retrieves and removes the first element from a deque?
pollFirst The pollFirst method will both retrieve and remove the head item.
Which of the following Java statements best septics the instantiating of the first element within a stack? 1. private Node tail; 2. public int push(); 3. private Node top; 4. public int pop;
private Node top; private Node top; private Node top;
What method is used to add data items to a stack in Java? push() submit() place() pop()
push(). push(). push(). push(). push(). push(). push().