Sunteți pe pagina 1din 4

CS 331

Chapter 7 Questions

1) Which of the following ADTs is like a line of people? a) list b) stack c) queue d) tree Answer: c. 2) In a queue, items can be added ______. a) only at the front of the queue b) only at the back of the queue c) either at the front or at the back of the queue d) at any position in the queue Answer: b. 3) Operations on a queue can be carried out at ______. a) its front only b) its back only c) both its front and back d) any position in the queue Answer: c. 4) Which of the following is NOT an ADT queue operation? a) enqueue b) isEmpty c) pop d) peek Answer: c. 5) The ______ operation retrieves and removes the front of a queue. a) isEmpty b) enqueue c) dequeue d) peek Answer: c. 6) The ______ operation adds a new item to a queue. a) enqueue b) dequeue c) push d) peek Answer: a. 7) The ______ operation retrieves the item that was added earliest to a queue, but does not remove that item. a) enqueue b) dequeue c) dequeueAll d) peek Answer: d. 8) Which of the following operations leaves a queue unchanged? a) enqueue b) dequeue c) dequeueAll d) peek Answer: d.

Page 1 of 4

CS 331

Chapter 7 Questions

9) A reference-based implementation of a queue that uses a linear linked list would need at least ______ external references. a) one b) two c) three d) four Answer: b. 10) A reference-based implementation of a queue that uses a circular linked list would need at least ______ external references. a) one b) two c) three d) four Answer: a. 11) Which of the following is the code to insert a new node, referenced by newNode, into an empty queue represented by a circular linked list? a) newNode.setNext(lastNode); b) lastNode.setNext(lastNode); lastNode = newNode; c) newNode.setNext(lastNode); newNode = lastNode; d) newNode.setNext(newNode); lastNode = newNode; Answer: d. 12) Which of the following methods of QueueInterface does NOT throw a QueueException? a) enqueue b) dequeue c) dequeueAll d) peek Answer: c. 13) To initialize a queue that is represented by a circular array, back is set to ______. a) 0 b) 1 c) MAX_QUEUE d) MAX_QUEUE - 1 Answer: d. 14) To initialize a queue that is represented by a circular array, front is set to ______. a) 0 b) 1 c) MAX_QUEUE d) MAX_QUEUE - 1 Answer: a. 15) The Java ______ operator is used to obtain the wraparound effect of a circular array-based queue. a) * b) + c) % d) / Answer: c.

Page 2 of 4

CS 331

Chapter 7 Questions

16) Which of the following code fragments is used to delete the item at the front of a queue represented by a circular array? a) front = MAX_QUEUE - front; --count; b) front = front - back; --count; c) front = (front+1) % MAX_QUEUE; --count; d) front = (back+1) % MAX_QUEUE; --count; Answer: c. 17) If a queue is implemented as the ADT list, which of the following queue operations can be implemented as list.remove(1)? a) enqueue() b) dequeue() c) isEmpty() d) peek() Answer: b. 18) If a queue is implemented as the ADT list, which of the following queue operations can be implemented as list.get(1)? a) enqueue() b) dequeue() c) isEmpty() d) peek() Answer: d. 19) In an implementation of a queue uses the ADT list, which of the following can be used to implement the operation enqueue(newItem)? a) list.add(list.size(), newItem) b) list.add(list.size()+1, newItem) c) list.add(newItem.size(), newItem) d) list.add(newItem.size()+1, newItem) Answer: b. 20) The ADT ______ allows you to insert into, delete from, and inspect the item at any position of the ADT. a) stack b) queue c) list d) array Answer: c. 21) Which of the following is an operation of the ADT stack? a) enqueue b) push c) add d) get Answer: b. 22) The pop operation of the ADT stack is similar to the ______ operation of the ADT queue. a) isEmpty b) enqueue c) dequeue d) peek Answer: c.

Page 3 of 4

CS 331

Chapter 7 Questions

23) The enqueue operation of the ADT queue is similar to the ______ operation of the ADT stack. a) isEmpty b) peek c) push d) pop Answer: c. 24) In the ADT list, items can be added ______. a) only at the front of the list b) only at the back of the list c) either at the front or at the back of the list d) at any position in the list Answer: d. 25) Which of the following is an operation of the ADT list? a) pop b) dequeue c) peek d) remove Answer: d.

Page 4 of 4

S-ar putea să vă placă și