Services
Discover
Homeschooling
Ask a Question
Log in
Sign up
Filters
Done
Question type:
Essay
Multiple Choice
Short Answer
True False
Matching
Topic
Computing
Study Set
Java Software Solutions
Quiz 13: Collections
Path 4
Access For Free
Share
All types
Filters
Study Flashcards
Practice Exam
Learn
Question 41
Essay
Two abstract data types are the ordered list and the unordered list. Explain how these two ADTs are similar and how they differ. To answer this question, assume that you do not know how they are implemented (that is, whether they are implemented using an array or a linked list).
Question 42
Multiple Choice
Example Code Ch 13-5 Consider the following operations on a queue data structure that stores int values: Queue q = new Queue() ; q.enqueue(3) ; q.enqueue(5) ; q.enqueue(9) ; System.out.println(q.dequeue() ) ; // d1 q.enqueue(2) ; q.enqueue(4) ; System.out.println(q.dequeue() ) ; // d2 System.out.println(q.dequeue() ) ; // d3 q.enqueue(1) ; q.enqueue(8) ; -Refer to Example Code Ch 13-5: What value is returned by the last dequeue operation, denoted with a d3 as a comment.
Question 43
Short Answer
Example Code Ch 13-1 The following is a class definition of a linked list Node: class Node { int info; Node next; } -Refer to Example Code Ch 13-1: Assume that head references a linked list and stores in order, the int values 3, 6 and 2. Show the instructions needed to delete the Node with 3 so that head would reference the list 6 and 2.
Question 44
Multiple Choice
Example Code Ch 13-5 Consider the following operations on a queue data structure that stores int values: Queue q = new Queue() ; q.enqueue(3) ; q.enqueue(5) ; q.enqueue(9) ; System.out.println(q.dequeue() ) ; // d1 q.enqueue(2) ; q.enqueue(4) ; System.out.println(q.dequeue() ) ; // d2 System.out.println(q.dequeue() ) ; // d3 q.enqueue(1) ; q.enqueue(8) ; -Refer to Example Code Ch 13-5: After this code executes, how many elements would remain in q?
Question 45
Essay
What is an ADT (Abstract Data Type) and why are ADTs considered to be abstract?
Question 46
Essay
A double-ended queue, called a dequeue, is a queue that, instead of having single links in one direction, has a pair of links, one pointed in each direction. Dequeues allow one to "push" and "pop" information at either end. Is this ADT the same or different from a doubly linked list, as described in the textbook?
Question 47
Essay
Example Code Ch 13-1 The following is a class definition of a linked list Node: class Node { int info; Node next; } -Refer to Example Code Ch 13-1: Show the instructions required to create a linked list that is referenced by head and stores in order, the int values 3, 6 and 2. Assume that Node's constructor receives no parameters.
Question 48
Essay
Example Code Ch 13-1 The following is a class definition of a linked list Node: class Node { int info; Node next; } -Refer to Example Code Ch 13-1: Assume that head references a linked list and stores in order, the int values 3, 2 and 6. Show the instructions needed to move the value 2 in front of the value 6 so that the list is now 3, 2 and 6.
Question 49
Multiple Choice
A simple linear list
Question 50
Essay
Example Code Ch 13-1 The following is a class definition of a linked list Node: class Node { int info; Node next; } -Refer to Example Code Ch 13-1: Assume that head references a linked list, although we don't know what is currently stored in that list. Write a block of code using a try-catch block that will work through the entire linked list, printing each element out, stopping only when we have reached the end of the list because a NullPointerException is thrown. Once the Exception is thrown, output the number of elements found in the list.
Question 51
Multiple Choice
Example Code Ch 13-5 Consider the following operations on a queue data structure that stores int values: Queue q = new Queue() ; q.enqueue(3) ; q.enqueue(5) ; q.enqueue(9) ; System.out.println(q.dequeue() ) ; // d1 q.enqueue(2) ; q.enqueue(4) ; System.out.println(q.dequeue() ) ; // d2 System.out.println(q.dequeue() ) ; // d3 q.enqueue(1) ; q.enqueue(8) ; -Refer to Example Code Ch 13-5: If we replace the System.out.println statements (denoted in comments as d1, d2 and d3) with the statement q.enqueue(q.dequeue() ) ; q would contain which order of int values after all instructions have executed?
Question 52
Multiple Choice
Example Code Ch 13-6 Assume a stack class stores int values. Consider the following sequence of instructions. Stack s = new Stack() ; s.push(16) ; s.push(12) ; s.push(19) ; int x = s.pop() ; s.push(5) ; s.push(9) ; s.push(4) ; int y = s.pop() ; int z = s.pop() ; -Refer to Example Code Ch 13-6: After the instructions execute, x has the value
Question 53
Essay
Challenge: Assume a function g(x) is defined as follows where x is an int parameter: g(x) = g(x - 1) * g (x - 3) if x is even and x > 3 = g(x - 2) if x is odd and x > 3 = x otherwise Write a recursive method to compute g. In implementing a queue using an array, a problem might arise if the queue is implemented in such a way that items in the queue are inserted at the next available location and removed from the next leading position, but such that, once deleted, the emptied space is unused. The problem that arises is one where there is free space still in the array, but it is not usable because it is not at the end. Demonstrate this problem with a queue that is stored in an array of size 5 for the following instructions. Next, explain how you might resolve this problem. Queue q = new Queue(5); // assume the Queue constructor takes 5 as the size of the array q.enqueue(3); q.enqueue(4); q.enqueue(1); q.dequeue(); q.dequeue(); q.enqueue(6); q.enqueue(5); q.dequeue(); // at this point, there are only 2 items in the queue q.enqueue(7); // this enqueue can not occur, why??
Question 54
Essay
What common exception(s) might arise when using an array? What common exception(s) might arise when using a linked list?
Question 55
Essay
A queue q stores int values. Show what q will look like after each of the following instructions is executed. q.enqueue(6); q.enqueue(12); q.enqueue(13); q.dequeue(); q.dequeue(); q.enqueue(19); q.enqueue(21); q.enqueue(22); q.dequeue(); q.enqueue(20);