2214 RealizeIT Module 4 Questions

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Assume you have a queue called nameQ that has the following items in it: "Peach", "Daisy", "Zelda", "Link". Peach is at the front/head of the queue. You then execute the following code: String s = nameQ.dequeue(); nameQ.enqueue("Luigi"); nameQ.enqueue("Mario"); What does the queue look like?

"Daisy", "Zelda", "Link", "Luigi", "Mario"

For the following code, what is returned? Assume that ArrayQueue is a correctly implemented class, with lots of capacity. Also note that we are using add/remove instead of enqueue/dequeue, which is just a different vocabulary. public String testQueue() throws EmptyCollectionException { String s; Queue<String> queue = new ArrayQueue<String>(); queue.add("d"); queue.add("y"); s = queue.remove(); queue.add("w"); queue.add("b"); s = queue.remove(); s = queue.remove(); return s; }

"w"

Which of the following are not true when working with linked list Queues? - Can view any element if you have the index - They function through FIFO - Can add at any index point - Able to see last element without removing it

- Can view any element if you have the index - Can add at any index point

Which of the following is/are required to build up a linear node class?

- Getter/Setter for next node - Default Constructor - Getter/Setter for element - Constructor with element or parameters - Getter/Setter for previous node (Double linked node only) - Implementation of generics

A singly-linked Queue, called myQueue, has the following structure: Lemon -> Honeydew -> Mango -> Peach Where Lemon is the 'front', Peach is the 'back', and the 'count' is 4. The following code is ran on this queue: firstDeq = myQueue.dequeue(); secondDeq = myQueue.dequeue(); myQueue.enqueue("Banana"); myQueue.enqueue(secondDeq); myQueue.enqueue("Lime"); myQueue.enqueue(firstDeq); Select all of the following that are true after this code has ran. - The next pointer of the node containing Mango points to the same node as the back pointer. - The back pointer of the queue refers to Peach. - The count field of the queue is equal to 6. - The next String that will be removed when dequeue() is called is Mango. - The String referenced by firstDeq is no longer closer to the front of the queue than the String referenced by secondDeq. - The front pointer of the queue refers to Lemon. - The next pointer of the node containing Peach points to the node containing Lemon.

- The count field of the queue is equal to 6. - The next String that will be removed when dequeue() is called is Mango. - The String referenced by firstDeq is no longer closer to the front of the queue than the String referenced by secondDeq.

Assume you have a stack, called myStack, implemented with single-linked nodes, that looks like this: m -> k -> e -> y 'top' is a reference variable that points to the node containing m, and 'count' is an internal int that holds the count of nodes (currently 4). The following code is ran: Character firstPop = myStack.pop(); Character secondPop = myStack.pop(); myStack.push(firstPop); myStack.push('w'); myStack.push(secondPop); myStack.push('t'); Select all of the following that are true at the end of this code.

- The variable firstPop refers to m. - The element w is contained by the third node in this stack (where 'top' is considered the first node). - The count if currently equal to 6. - The character held by secondPop is now the element contained by the node reference through top's next pointer.

For the operation QueuePop(queue), what is the second parameter passed to ListRemove after?

0

A Queue that has been implemented with a singly-linked list has the following structure: p -> a -> m -> l -> y -> w Where p is the 'front' of the queue, w is the 'back', and the 'count' is 6. What would the psuedocode for dequeueing an element look like?

1. Create a new Character called temp 2. Set temp to the front's element pointer 3. Set the front pointer to the current front's next pointer 4. Decrement count 5. Return temp

A Queue that has been implemented with a singly-linked list has the following structure: b -> f -> v -> p -> w Where b is the 'front' of the queue, w is the 'back', and the 'count' is 5. What would the psuedocode for enqueueing a new element, r, look like?

1. Create a new singly-linked node called temp 2. Set temp's element pointer to r 3. Set the back node's next pointer to temp 4. Set the back pointer to temp 5. Increment count

Assume you have a stack implemented with single-linked nodes, that looks like this: l -> y -> h -> d -> e -> j 'top' is a reference variable that points to the node containing l, and 'count' is an internal int that holds the count of nodes (currently 6). If you want to do pop operation, what is the pseudocode to achieve this?

1. create a Character called temp 2. set temp's pointer to be the same as top's element pointer 3. set top's pointer to be the same as top's next pointer 4. decrement count 5. return temp

Assume you have a stack implemented with doubly-linked nodes, that looks like this: Dragonfruit -> Pear -> Mango -> Pineapple -> Banana 'top' is a reference variable that points to the node containing Dragonfruit, and 'count' is an internal int that holds the count of nodes (currently 5). If you want to do push operation with the value Lime, what is the pseudocode to achieve this?

1. create a doubly linked node called temp 2. set temp's element pointer to Lime 3. set temp's next pointer to be the same as top 4. set top's previous pointer to be the same as temp 5. set top to point at temp 6. increment count

Assume you have a stack implemented with single-linked nodes, that looks like this: 282 -> 789 -> 93 -> 261 -> 89 'top' is a reference variable that points to the node containing 282, and 'count' is an internal int that holds the count of nodes (currently 5). If you want to do push operation with the value 275, what is the pseudocode to achieve this?

1. create single linked node called temp 2. set temp's element pointer to 275 3. set temp's next pointer to be the same as top 4. set top to point at temp 5. increment count

Assume you have a linked list data structure with f nodes. It is a singly-linked list that supports generics, so it can hold any type of object. How many reference are in this data structure, including references that are null?

2f+1

If you have a queue with 800 items in it, how many linear nodes would be in use?

800

Given the following code using a queue X: X.enqueue(new Integer(6)); X.enqueue(new Integer(7)); Integer y = X.dequeue(); X.enqueue(new Integer(9)); X.enqueue(new Integer(2)); X.enqueue(y); X.enqueue(new Integer(1)); y = X.dequeue(); X.enqueue(new Integer(7)); X.enqueue(new Integer(8)); What is the value returned by X.first()

9

Which of the following statements about Java interfaces is most accurate? - A Java interface is an unfinished template for a class or project. - A Java interface indicate the exact number of method, and their names, an implementation will have. - A Java interface defines how an implementation of it must accomplish its methods. - A Java interface demonstrates the methods an implementation of it must accomplish.

A Java interface demonstrates the method an implementation of it must accomplish

Which of the following statements is NOT true about implementations of interfaces? - An implementation can overload any methods specified by the interface, as long as at least one of them includes the specified parameters. - An implementation can have less methods than its interface specifies. - An implementation can have more methods than its interface specifies. - An implementation can accomplish a method specified by its interface in any way the programmer pleases, as long as the method is there.

An implementation can have less methods than its interface specifies.

A linked list has what key advantage over a sequential storage approach like an array or ArrayList?

An item can be inserted somewhere in the middle

How many interface could a Java class implement?

Any amount

What assert calls do you need to test that a dequeue() operation works on a queue of String objects? Assume result is what the dequeue operation returns, expResult is what you think you should get, and instance is the collection. You have created the instance, and just added one element to it, then you removed it.

AssertEquals(result, expResult); AssertEquals(instance.size(), 0);

A queue processes elements in a ___ manner.

FIFO (First in, first out)

A Queue is a LIFO

False

True or False: The top variable keeps track of the number of elements in a LinkedStack implementation

False

Declare a variable called numRabbit that refers to a primitive wrapper object with an int value of 61. Use the object initialization style.

Integer numRabbit = new Integer(61);

While you can us an array to create a queue, it turns out that ____ are much more suitable.

Linear Nodes

Which of the following is the output of the below code: import java.util.*; public class QueueSamples { public static void main (String [ ] args) { Queue <String> names = new LinkedList< >(); names.add("Mark"); names.add("Elizabeth"); names.add("Isabella"); names.add("Jack"); System.out.println(names.remove()); } } - Mark - Isabella - Elizabeth - Jack

Mark

For the following code, what is returned? public String testQueue() throws EmptyCollectionException { String s; Queue<String> queue = new ArrayQueue<String>(); queue.add("a"); queue.add(c"); s = queue.remove(); s = queue.remove(); s = queue.remove(); queue.add(d"); queue.add("b"); s = queue.remove(); s = queue.remove(); return s; }

Nothing, an exception is thrown.

For the following code, what is returned? public String testQueue() throws EmptyCollectionException { String s; Queue<String> queue = new ArrayQueue<Integer>(); queue.add("b"); queue.add("c"); s = queue.remove(); s = queue.remove(); queue.add("x"); queue.add("d"); s = queue.remove(); s = queue.remove(); return s; }

Nothing, the code won't compile

The interface Edible has an abstract method void eat(). Which of the following does a class Apple NOT have to do to make use of this interface? - Indicate that Apple implements Edible. - Override the void eat() method. - Implement the void eat() method. - Overload the void eat() method.

Overload the void eat() method.

What's the purpose of a list's head node?

Provides a reference to the first item's node in the list, if it exists.

Which of the following data structures allow deletion from the front and insertion from the end (rear) ? - Queue - Stack - Linked List - Linked Node

Queue

Which of the following lines of code will compile? Assume that all needed files have been imported. Select all that apply. - Queue<String> strings = new LinkedList<String>(); - Queue<String> strings = new LinkedList(); - Queue strings = new Queue(); - Queue<Strings> strings = new Queue();

Queue<String> strings = new LinkedList<String>(); Queue<String> strings = new LinkedList();

Queues and ____ are similar in that they are data structures that are designed for a temporarily holding data.

Stacks

Which of the following is NOT a difference between Stacks and Queues? - Stacks are Last-In First-Out (LIFO), while Queues are First-In First-Out (FIFO) - Stacks must utilize LinkedLists, while Queues must utilize ArrayLists - Stacks add elements by 'pushing' them, while Queues add elements by 'enqueueing' them. - Stacks are ideal for situations such as implementing an undo button, while Queues are ideal for situations such as a handling help requests in the order they're recieved.

Stacks must utilize LinkedLists, while Queues must utilize ArrayLists.

What makes implementing a queue with a Linked List potentially easier than implementing a queue with a typical array?

There's no need to explicitly shift the elements of a LinkedList to the front, as there would be in an array.

True or False: In implementing the push, pop, and peek StackADT methods using a linked structure, you never have to iterate through the entire set of linear nodes.

True

True or False: It is possible for the head and tail pointers in a linked list queue implementation to point at the same node.

True

True or False: StackPop points a local variable to the list's head node.

True

What is the benefit of implementing a stack with a linked linear node structure, as opposed to an array?

You won't run out of capacity like with an array, and have to create and copy a whole new structure.

Which of the following is the output of the below code ? import java.util.*; public class Queue { public static void main (String [ ] args) { Queue <Integer> queue = new LinkedList<>(); queue.add(77); queue.add(16); queue.add(6); System.out.println(queue); } } - [16, 6, 77] - [16, 77, 6] - [6, 77, 16] - [77, 16, 6]

[77, 16, 6]

Which of the following test asserts pass when evaluated against a queue instance with 1 item in it? - assertTrue(instance.isEmpty()); - assertEquals(instance.size(), 1); - assertFalse(!instance.isEmpty()); - assertNull(instance);

assertEquals(instance.size(), 1);

A queue is appropriate for which of the following domains: - contact list - maze navigation - undo tracking - call center call processing

call center call processing

Because a linear node holds a reference to a generic object, we call it a:

container

Which Java queue operations throw exceptions?

element() remove()

When using a Queue implemented with Linked Nodes how would you gain access to the element of the second node in the list?

head.getNext().getElement();

Assume the queue is implemented using a linked list. If the head pointer is null, the queue____

is empty

For the operation QueuePop(queue), poppedItem contains a pointer to the _____.

list head

A class is defined to represent each list item, known as a ____

list node

Linked nodes have this advantage over arrays for implementing collections:

no capacity issues

Assume the stack is implemented using a linked list. An empty stack is indicated by a list head pointer value of _____

null

Which of the following methods allows you to return the head from a Queue, removing it and not throw an exception if the Queue is empty? - poll() - peek() - element() - remove()

poll()

There are two types of liner nodes:

singly-linked and doubly-linked

A stack is often implemented using a linked list, with the list's head node being the stack's _____

top

While float is a primitive variable, Float is a _____

wrapper variable


Set pelajaran terkait

Assessment Related to Acid-Base Balance

View Set

U.S. History American Economic Expansion

View Set

Quiz 1: Chapter 13 Social Psychology

View Set

Mental Health, Dementia, Piaget's Adaptive Quizzing

View Set

OCI Architect Associate (1Z0-1072)

View Set