Queues/Deques, Generics

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

To efficiently remove a node at the end of a linked chain implementation of a queue with a tail reference requires a traversal extra reference in the node pointing to the previous node none of the above

extra reference in the node pointing to the previous node

What type of behavior defines a queue? last-in first-out first-in first-out none of the above first-in last-out

FIFO

Which combination of statements are True? Statements: I. The question mark (?) is a wildcard or placeholder, representing an unknown type II. In the statement "? extends MyClass", the ? represents a subtype of MyClass where MyClass represents an Upper Bound III. In the statement "? extends MyClass", the ? represents a supertype of MyClass where MyClass represents a Lower Bound I and II I and III II and III All of the above

I and II

In a linked chain implementation of a queue, the performance of the enqueue operation is O(1) O(logn) O(n) O(n^2)

O(1)

Suppose QueueADT is implemented using a singly linked list. What is the lowest Big-Oh time complexity that can be achieved for an enqueue method?: O(1) O(log2 n) O(n) O(n2) none of the above

O(1)

Based on the deque class shown in the videos. What does this code most likely do: firstNode = firstNode.getNext(); if (firstNode == null) lastNode = null; else firstNode.setPreviousNode(null); Removes the first node from a singly linked chain Removes the first node from a doubly linked chain Iterates through a singly linked chain Iterates through a doubly linked chain

Removes the first node from a doubly linked chain

What item is at the front of the deque 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(); Jack Correct Answer Rudy Larry You Answered Sam

Rudy

What item is at the front of the deque 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(); Jack Rudy Larry Sam

Rudy

Is the following statement True or False? Statement: Bounded type parameters allows developers to restrict the types that can be used as type arguments in a parameterized type. True False

True

Is the following statement True or False? Statement: To declare generic methods we write methods using the format methodModifiers <genericTypeParameters> returnType methodName(methodParameters) True False

True

When a linked chain contains nodes that reference both the next node and the previous node, it is called a(n) multi-linked chain two-way linked chain doubly linked chain ordinary chain

doubly linked chain

In the linked chain implementation of a queue, the chain's first node contains the queue's front entry the queue's back entry both a & b none of the above

the queue's front entry

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" "jaguar" "tiger" "lion"

"cheetah"

Given a full queue in an array contents that is storing the values {'Y','E',null,'N','O','T'} What happens when enqueue('T') is called? Once the demonstrated ensureCapacity method is executed, what will be store in contents[1]? 'Y' 'E' 'N' 'O' Null

'O'

Which of the following would correctly complete the isEmpty() method for a linked implementation of a deque in all cases Public boolean isEmpty() { return < fill in code here >; } (firstNode == null) && (lastNode == null) (firstNode == null) (lastNode == null) (firstNode == lastNode)

(firstNode == null) && (lastNode == null) (firstNode == null) (lastNode == null)

We know that using Generics reduces the need to cast types. Which of the following answers best conveys some of the other benefit(s) of using generics and parameterized or generic types in Java? Generics provide type safety and enable strong type checks at compile time Provide developers with the ability to implement generic algorithms (classes and methods) All of the above

All of the above

public T removeFront() { T front = getFront(); firstNode = firstNode.getNext(); if(firstNode == null) { lastNode = null; } else { firstNode.setPrev(null); } return front; } What will happen if removeFront() is called on an empty deque? Null will be returned An EmptyDequeException will be thrown An EmptyQueueException will be thrown firstNode.data will be returned lastNode.date will be returned

An EmptyDequeException will be thrown

Which of the following is more restrictive? ArrayList<Integer> myList; ArrayList<? super Integer> myList;

ArrayList<Integer> myList;

ArrayList<? super Customer> myCustomer; Which of the following is True?; In the statement "? super Customer", the ? is a placeholder that represents a subtype of Customer where Customer represents an Upper Bound In the statement "? super Customer", the ? represents a Customer type or a super type of Customer, where Customer is considered to be the Lower Bound

In the statement "? super Customer", the ? represents a Customer type or a super type of Customer, where Customer is considered to be the Lower Bound

Keeping track of lastNode in addition to firstNode (Select all that apply) Makes enqueue operations O(1) Makes dequeue operations O(n) Causes lastNode to need to be updated every time an item is dequeued Causes lastNode to need to be updated if the only item in the queue is dequeued Causes lastNode to need to be updated every time an item is enqueued Causes lastNode to need to be updated only when the first item is enqueued

Makes enqueue operations O(1) Causes lastNode to need to be updated if the only item in the queue is dequeued Causes lastNode to need to be updated every time an item is enqueued

Based on the deque class shown in the videos. Given the following member method: public void addToFront(T newEntry) { DLNode newNode = new DLNode(null,newEntry,firstNode); if (isEmpty()) { lastNode = newNode; } else { firstNode.setPrev(newNode); } firstNode = newNode; } If "Jeep Wrangler" is passed as a parameter to newEntry. What will the prev field of the node containing "Jeep Wrangler" reference? Null firstNode lastNode firstNode and lastNode

Null

In a circular array-based implementation of a queue, what is the performance when the dequeue operation ? O(1) O(logn) O(n) O(n^2)

O(1)

public T removeFront() { T front = getFront(); firstNode = firstNode.getNext(); if(firstNode == null) { lastNode = null; } else { firstNode.setPrev(null); } return front; } Select all of the following that will happen if removeFront() is called on a deque with 3 items? firstNode and lastNode will become null The first node of the three will be removed The last node of the three will be removed firstNode.data will be returned lastNode.data will be returned

The first node of the three will be removed firstNode.data will be returned

Where does a queue add new items? in the middle at the front randomly at the back

at the back

Where will you find the item added earliest to a queue? randomly in the middle at the back at the front

at the front

Given that backIndex references the last element of the queue stored in a contents array, which of the following best describes how to update backIndex when a new entry is successfully enqueued: frontIndex ++ backIndex ++ frontIndex = ( frontIndex + 1) % contents.length backIndex = ( backIndex + 1) % contents.length

backIndex = ( backIndex + 1) % contents.length

Consider a generic method declared as depicted below, with type parameter <T extends Number> and two method parameters both of type T: public <T extends Number> void specialMethod(T first, T second) client code can provide any value for the type parameter T client code can only provide type Number or any subclass of Number for the type parameter for T None of the above

client code can only provide type Number or any subclass of Number for the type parameter for T

If an ArrayQueue is stored an array contents with 1 unused element, which of the following are true (select all that apply): contents.length -1 indicates the capacity of the queue The number of elements in the queue will always be contents.length If size represent the number of elements in the arrayqueue then its range is 0 <= size < contents.length If size represent the number of elements in the arrayqueue then its range is 0 <= size <= contents.length

contents.length -1 indicates the capacity of the queue If size represent the number of elements in the arrayqueue then its range is 0 <= size < contents.length

public T removeFront() { T front = getFront(); firstNode = firstNode.getNext(); if(firstNode == null) { lastNode = null; } else { firstNode.setPrev(null); } return front; } Select all of the following that will happen if removeFront() is called on a deque with 1 item? firstNode and lastNode will become null firstNode.next will be returned lastNode.prev will be returned firstNode.data will be returned lastNode.data will be returned

firstNode and lastNode will become null firstNode.data will be returned lastNode.data will be returned

Given an array queue implementation with one unused entry and frontIndex and backIndex references, match the status of the queue with the following information about frontIndex and backIndex for a queue with capacity of 5: frontIndex is 0 and backIndex is 4 empty queue one element in the queue three elemenst in the queue four elements in the queue five elements in the queue six elements in the queue invalid

five elements in the queue

Given an array queue implementation with one unused entry and frontIndex and backIndex references, match the status of the queue with the following information about frontIndex and backIndex for a queue with capacity of 5: frontIndex is 1 and backIndex is 4 empty queue one element in the queue three elements in the queue four elements in the queue five elements in the queue six elements in the queue invalid

four elements in the queue

Given an array queue implementation with one unused entry and frontIndex and backIndex references, match the status of the queue with the following information about frontIndex and backIndex for a queue with capacity of 5: frontIndex is 3 and backIndex is 0 empty queue one element in the queue three elements in the queue four elements in the queue five elements in the queue six elements in the queue invalid

four elements in the queue

Suppose we have a Queue implemented with a circular array. The capacity is 10 and the size is 5. Which are legal values for front and rear? front: 0 rear: 5 front: 5 rear: 9 front: 7 rear: 2 front: 9 rear: 4 all of the above

front: 5 rear: 9

Given an array queue implementation with one unused entry and frontIndex and backIndex references, match the status of the queue with the following information about frontIndex and backIndex for a queue with capacity of 5: frontIndex is 0 and backIndex is -1 empty queue one element in the queue three elements in the queue four elements in the queue five elements in the queue six elements in the queue invalid

invalid

Given an array queue implementation with one unused entry and frontIndex and backIndex references, match the status of the queue with the following information about frontIndex and backIndex for a queue with capacity of 5: frontIndex is 0 and backIndex is 0 empty queue one element in the queue three elements in the queue four element in the queue five elements in the queue six elements in the queue invalid

one element in the queue

Given an array queue implementation with one unused entry and frontIndex and backIndex references, match the status of the queue with the following information about frontIndex and backIndex for a queue with capacity of 5: frontIndex is 2 and backIndex is 2 empty queue one element in the queue three elements in the queue four elements in the queue five elements in the queue six elements in the queue invalid

one element in the queue

In a circular array-based implementation of a queue, the initial size of the array should be two more than the queue's initial capacity two less than the queue's initial capacity one more than the queue's initial capacity one less than the queue's initial capacity

one more than the queue's initial capacity

The dequeue operation: adds a new item at the front of a queue returns without removing the item at the front of a queue removes and returns the item at the front of a queue adds a new item at the end of a queue returns true if a queue is empty and otherwise false

removes and returns the item at the front of a queue

Based on the deque class shown in the videos. Given the following member method: public T removeBack(){ T back = getBack(); lastNode = lastNode.getPrev(); if (lastNode == null) firstNode = null; else lastNode.setNext(null); return back; } What is the case that is covered when the expression (lastNode == null) is true? .removing from a deque with items only at the front removing from a full deque removing from an empty deque removing from a deque with one item

removing from a deque with one item


संबंधित स्टडी सेट्स

Life and Health Insurance ExamFx

View Set

Philosophy 230 Knowledge and Reality

View Set

Life Insurance Policies (Chapter 3)

View Set

Self Test: Basics of Medical Terminology

View Set