CPSC 221 - (CH. 12 - 14) Quiz

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

Java provides a Queue class that implements a pure queue collection implementation (T/F).

False

The dequeue operation should throw an exception if it removes the last element in the queue (T/F).

False

The isEmpty() method determines if the store of extra memory for use by the stack is empty (T/F).

False

The peek operation can retrieve a value from anywhere in the stack(T/F).

False

The peek operation on a stack returns a reference to the element at the bottom of the stack (T/F).

False

Using the rear of the linked linear collection as the top of the stack is the most efficient way to manage the stack (T/F).

False

When working with a linked linear collection implementation of a stack, the push operation should throw an exception if the stack is empty (T/F).

False

The postfix expression 5 3 * 2 5 + - 4 * 2 / evaluates to 16 (T/F).

True

A linked linear collection can hold ______ nodes a. any number of b. 100 c. a number specified when the linked list is instantiated. d. 1000 e. 10

a. any number of

Which of the following methods removes an element from a queue? a. dequeue b. first c. push d. pop e. enqueue

a. dequeue

Which of the following methods removes an element from a queue? a. dequeue b. pop c. enqueue d. push e. first

a. dequeue

Which of the following is not part of the pop operation for a stack implemented using a linked linear collection? a. determine if the stack is full b. determine if the stack is empty c. declare a temporary reference variable and set it to point to the element at the top of the stack d. adjust the top reference variable to point to the node pointed to by the next field of the node at the top of the stack e. all of these are part of the pop operation for a stack implemented using a linked linear collection

a. determine if the stack is full

As with queues and stacks, the first step in removing an element from a list collection is to a. determine that the collection is not empty. b. determine if the element is in the collection. c. determine if the element is in the first or the last position in the collection. d. determine if the collection will be empty once the element is removed. e. none of these is a reasonable first step in removing an element from a collection.

a. determine that the collection is not empty.

A(n) _____________________ is a data structure that uses object reference variables to create links between objects. a. link structure b. exception structure c. interface d. stack e. array-based data structure for a stack

a. link structure

The first operation of a queue is similar to the ______ operation of a stack a. peek b. size c. pop d. isEmpty e. push

a. peek

A(n) ____________________ is another way to refer to an object reference variable. a. pointer b. stack collection c. referer d. instantiated object e. primitive variable

a. pointer

In an array implementation of a stack, we can include code that will automatically allocate more memory if every element of the array is occupied. Which stack operation should invoke this code? a. push b. pop c. peek d. poke e. none of the above

a. push

The pointer to the first element in a linked linear collection a. should only be modified by the code that adds nodes to the collection and deletes nodes from the collection b. can be modified in any way necessary c. can be used to traverse the collection d. is inefficient e. is optional

a. should only be modified by the code that adds nodes to the collection and deletes nodes from the collection

Java provides two Collections classes that can be used to implement stacks. They are ______ and _____. a. the Stack class, the LinkedList class b. one-dimensional arrays, multidimensional arrays c. Exceptions, Errors d. data structures, list structures e. none of the above

a. the Stack class, the LinkedList class

Which of the following stack operations is not likely to cause an exception to be thrown? a. adding an item to the stack when the stack is full b. adding an item that has the same value as one that is already in the stack c. removing an item when the stack is empty d. all of a), b), and c) e. All of these are likely to cause an exception to be thrown

b. adding an item that has the same value as one that is already in the stack

Which of the following is not a queue operation? a. enqueue b. dequeue c. first d. isEmpty e. all of the above are queue operations

e. all of the above are queue operations

An abstract datatype is a data type that is not known to the programmer (T/F).

False

An object can only contain one field that is a reference to another object of the same type (T/F).

False

In a circular array-based implementation of a queue, the elements must all be shifted when the dequeue operation is called (T/F).

False

In a linked linear collection implementation of a queue, the enqueue operation compares the element to be added against the existing elements in the queue to determine the correct place to insert it (T/F).

False

In the linked collection implementation of a stack, capacity represents the number of elements for which space is allocated when the list is instantiated (T/F).

False

It is only possible to implement a queue using an array-based structure (T/F).

False

It is only possible to implement a stack using a linked structure (T/F).

False

A linked linear collection is a linear ordering of objects in which an object has a reference to the next object in the collection (T/F).

True

A postfix expression can be easily evaluated using a stack (T/F).

True

A queue is a FIFO structure (T/F).

True

A stack is a LIFO structure (T/F).

True

An array-based implementation of a stack can be designed so that all stack operations are O(1) (T/F).

True

An exception should be thrown if an attempt is made to pop an item from an empty stack (T/F).

True

In a circular array implementation of a queue, the front and rear references can change so that the value in front is greater than the value in rear (T/F).

True

In a circular array implementation of a queue, the remainder operator (%) can be used to calculate the value of the rear reference in an enqueue operation (T/F).

True

In a doubly linked linear collection, each element has a reference to the element that immediately precedes it in the collection and the element that immediately follows it in the collection (T/F).

True

In a linked implementation of a stack, a pushed element should be added to the end of the collection (T/F).

True

In a linked linear collection implementation of a queue, the dequeue operation is more efficient if it removes elements from the front of the linked linear collection than if it removes elements from the rear of the linked linear collection (T/F).

True

When working with a linked linear collection, the first element of the collection must be treated in a different way than the other elements (T/F).

True

A circular array has 20 elements. The index (array subscript) ranges from 0 to 19. What is the subscript of the array element that follows the element with subscript 19? a. 0 b. an exception will be thrown c. 1 d. 20 e. 21

a. 0

The constructor for a stack implemented using a linked list creates space for how many elements? a. 0 b. 10 c. 100 d. 1000 e. however many the programmer specified when the linked linear collection was instantiated.

a. 0

A stack is a ___________________ data structure. a. LIFO b. FIFO c. link based d. array based e. none of the above

a. LIFO

In an ideal implementation of a stack, all operations are ______________________ . a. O(1) b. O(n) c. O(n log n) d. O(n2) e. it depends on the operation

a. O(1)

In an ideal implementations of a queue, all operations are ______________________ . a. O(1) b. O(n) c. O(n log n) d. O(n2) e. it depends on the operation

a. O(1)

The peek operation of a stack is _________ a. O(1) b. O(n) c. O(n2) d. O(n log n) e. none of the above

a. O(1)

_____________________ is one of the most important computer resources a. The CPU time needed by a running program b. The size of the computer monitor c. A wireless mouse d. A wireless keyboard e. The number of disk drives that a computer has

a. The CPU time needed by a running program

In a queue implemented using a circular array, rear refers to a. the first available array element at the end of the queue b. the element at the end of the queue c. the number of elements remaining to be used at the end of the array d. the number of elements available at the beginning of the array e. none of the above

a. the first available array element at the end of the queue

What is the result of evaluating the following postfix expression: 4 8 + 2 * a. 40 b. 24 c. 64 d. 20 e. none of the above are correct

b. 24

A queue is a ____________________ data structure. a. LIFO b. FIFO c. link based d. array based e. none of the above

b. FIFO

A(n) ______ is an object that gathers and organizes other objects. a. abstraction b. collection c. exception d. algorithm e. none of the above

b. collection

A stack is the ideal collection to use when _______________________. a. implementing a radix sort b. evaluating a postfix expression c. modeling customers standing in line at the checkout of a grocery store d. finding the largest number in an array e. none of the above

b. evaluating a postfix expression

Java uses ________ to allow us to define a class and not specify the type of the objects that the class employs until the class is instantiated. a. inheritance b. generic types c. exceptions d. interfaces e. widgets

b. generic types

Creating a separate node class that holds a reference to another node and a reference to an object that is being stored in a collection is a good design because it a. makes the code more complicated b. hides the implementation details of a collection c. reduces code reuse d. all of the above e. neither a, b nor c

b. hides the implementation details of a collection

Java provides the Queue _____ to create programs that use the queue data structure. a. child b. interface c. parent d. class e. interlude

b. interface

Which of the following methods inserts an element into a stack data structure? a. dequeue b. push c. peek d. enqueue e. pop

b. push

Traversing a linked linear collection is a. the process of deleting the collection b. the process of visiting every node for some purpose c. the process of removing every node, one at a time d. the process of creating a new linked linear collection with twice the capacity e. none of the above

b. the process of visiting every node for some purpose

Which of the following is not a valid postfix expression? a. 5 4 + b. 6 5 4 + - c. 4 + 5 d. 8 2 + 2 / e. all of the above are valid postfix expressions

c. 4 + 5

In Java, type compatibility is enforced by _____________. a. Java does not enforce type compatibility b. convention c. compile-time type checking d. an Enforcer object e. an exception

c. compile-time type checking

The push operation of a stack implemented using a linked linear collection is O(1) when a. the stack is empty b. the stack is full c. the top of the stack is at the front of the linked linear collection d. the top of the stack is at the end of the linked linear collection e. none of the above

c. the top of the stack is at the front of the linked linear collection

One reason to define a Queue ADT (abstract data type) interface is a. to tightly couple the data in the queue elements with the implementation of the queue data structure b. to guide the programmer in how to implement the queue operations c. to separate the operations from the ways that the operations can be implemented d. both b) and c) are correct e. none of these is correct

c. to separate the operations from the ways that the operations can be implemented

What exception is thrown if the pop method is called on an empty stack, implemented using the ArrayStack class? a. EmptyStackException b. NoSuchElementException c. ArrayOutOfBoundsException d. EmptyCollectionException e. none of the above

d. EmptyCollectionException

Which of the following statements is generally true about a linked linear collection implementation of a queue? a. Elements are added (enqueue) and removed (dequeue) at the front of the linked linear collection. b. Elements are added (enqueue) and removed (dequeue) at the rear of the linked linear collection. c. The first operation retrieves the element that was most recently added to the linked linear collection. d. The linked linear collection implementation of a queue maintains references to both ends, the front and the rear, of the linked linear collection. e. All of the above statements are generally true about a linked linear collection implementation of a queue.

d. The linked linear collection implementation of a queue maintains references to both ends, the front and the rear, of the linked linear collection.

A Stack interface is defined and has an isEmpty() abstract method. What should this method return? a. an int representing the number of items in the stack b. a double representing the average of the values of the items in the stack c. a String representing the contents of the items in the stack. d. a boolean value representing whether the stack is empty or not. e. the item that is at the top of the stack

d. a boolean value representing whether the stack is empty or not.

Which of the following situations could be implemented using a Stack? a. cars waiting to pay and exit a parking garage b. people who have appointments in the reception area of a doctor's office c. students passing through the serving line in a cafeteria d. a person who wants to un-do several changes that were made to the document that she is editing. e. none of the above

d. a person who wants to un-do several changes that were made to the document that she is editing.

Which of the following are affected by an enqueue operation? a. the count of the number of elements in the queue b. the reference to the rear of the queue c. the reference to the front of the queue d. both a) and b) are true e. all of a), b), and c) are true

d. both a) and b) are true

Which of the following is not an operation on a stack? a. push b. pop c. peek d. dequeue e. all of the above are operations on a stack

d. dequeue

Which of the following should be performed first in a dequeue operation? a. declare and initialize reference to the node to be removed from the queue b. adjust the reference to the front of the queue c. decrement the count of the number of elements in the queue d. determine if the queue is empty e. These steps can be performed in any order.

d. determine if the queue is empty

A self-referential object is an object that a. is its own parent class b. is its own child class c. has a pointer to itself d. has a pointer to another object of the same type e. none of these is correct

d. has a pointer to another object of the same type

Which of the stack operations must be supported in a linked linear collection implementation? a. push and pop b. push and peek c. pop and peek d. push, pop, and isEmpty e. all of them

e. all of them

The queue operation that returns the element after the element at the front of the queue (that is, the second element in the queue) without removing the element at the front of the queue, is ________. a. dequeue b. dequeueNext c. bypass d. dequeueAndPeek e. none of these is correct

e. none of these is correct


Set pelajaran terkait

Chapter 24: Growth and Development of the Toddler: 1 to 3 Years

View Set

CSCI-1170-01 Askar Nurbekov Code Completion

View Set

Chapter 10 Section B Single Pilot Resource Management

View Set

CH 3 Working with Financial Statements

View Set

Ch. 25 Gastrointestinal Dysfunction Evolve Quiz

View Set