Chapter 24

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

________ is a data structure to store data in sequential order.

A list

Which of the following are true? A. A stack can be viewed as a special type of list, where the elements are accessed, inserted, and deleted only from the end, called the top, of the stack. B. A queue represents a waiting list. A queue can be viewed as a special type of list, where the elements are inserted into the end (tail) of the queue, and are accessed and deleted from the beginning (head) of the queue. C. Since the insertion and deletion operations on a stack are made only at the end of the stack, using an array list to implement a stack is more efficient than a linked list. D. Since deletions are made at the beginning of the list, it is more efficient to implement a queue using a linked list than an array list.

A. A stack can be viewed as a special type of list, where the elements are accessed, inserted, and deleted only from the end, called the top, of the stack. B. A queue represents a waiting list. A queue can be viewed as a special type of list, where the elements are inserted into the end (tail) of the queue, and are accessed and deleted from the beginning (head) of the queue. C. Since the insertion and deletion operations on a stack are made only at the end of the stack, using an array list to implement a stack is more efficient than a linked list. D. Since deletions are made at the beginning of the list, it is more efficient to implement a queue using a linked list than an array list.

LinkedList is more efficient than ArrayList for the following operations: A. Insert/delete an element in the middle of the list. B. Insert/delete an element in the beginning of the listc. Insert/delete an element at the end of the list. D. Retrieve an element given the index.

A. Insert/delete an element in the middle of the list. B. Insert/delete an element in the beginning of the listc. Insert/delete an element at the end of the list.

Which of the following statements are true? A. MyArrayList and MyLinkedList are two concrete implementations of MyList. B. MyArrayList is implemented using an array. The array is dynamically created. If the capacity of the array is exceeded, create a new larger array and copy all the elements from the current array to the new array. C. MyLinkedList is implemented using a linked structure. D. A linked structure consists of nodes. Each node is dynamically created to hold an element. All the nodes are linked together to form a list. E. MyAbstractList partially implements MyList.

A. MyArrayList and MyLinkedList are two concrete implementations of MyList. B. MyArrayList is implemented using an array. The array is dynamically created. If the capacity of the array is exceeded, create a new larger array and copy all the elements from the current array to the new array. C. MyLinkedList is implemented using a linked structure. D. A linked structure consists of nodes. Each node is dynamically created to hold an element. All the nodes are linked together to form a list. E. MyAbstractList partially implements MyList.

n the implementation of MyLinkedList, which of the following are true? A. MyLinkedList contains all the methods defined in MyList. Additionally, MyLinkedList defines several new methods that are appropriate for processing a linked list. B. MyArrayList does not introduce new methods. All the methods in MyArrayList are defined in MyList. C. You can use a linked list to improve efficiency for adding and removing an element anywhere in a list. D. You should use an array list if your application does not require adding and removing an element anywhere in a list.

A. MyLinkedList contains all the methods defined in MyList. Additionally, MyLinkedList defines several new methods that are appropriate for processing a linked list. B. MyArrayList does not introduce new methods. All the methods in MyArrayList are defined in MyList. C. You can use a linked list to improve efficiency for adding and removing an element anywhere in a list. D. You should use an array list if your application does not require adding and removing an element anywhere in a list.

In the implementation of MyLinkedList, which of the following are true? A. Node is defined as an inner class inside MyLinkedList. B. Node is defined as a static inner class inside MyLinkedList because it does not reference any instance data fields in MyLinkedList. C. Node has a property named next that links to the node after this node. D. Node has a property named element that stores an element.

A. Node is defined as an inner class inside MyLinkedList. B. Node is defined as a static inner class inside MyLinkedList because it does not reference any instance data fields in MyLinkedList. C. Node has a property named next that links to the node after this node. D. Node has a property named element that stores an element.

Which of the following operations are supported by a list? A. Retrieve an element from this list. B. Insert a new element to this list. C. Delete an element from this list. D. Find how many elements are in this list. E. Find whether an element is in this list.

A. Retrieve an element from this list. B. Insert a new element to this list. C. Delete an element from this list. D. Find how many elements are in this list. E. Find whether an element is in this list.

In the implementation of MyArrayList, which of the following are true? A. size indicates the number of elements in the list. B. capacity is the length of the array used to store the elements in the list. C. capacity is always greater than size. D. size is reduced by 1 if an element is deleted from the list. E. capacity is reduced by 1 if an element is deleted from the list.

A. size indicates the number of elements in the list. B. capacity is the length of the array used to store the elements in the list. D. size is reduced by 1 if an element is deleted from the list.

is efficient in O(1) time for appending elements, for retrieving elements from a given index.

ArrayList

In the implementation of MyLinkedList, which of the following are true? A. MyLinkedList has a capacity property. B. MyLinkedList has the properties named first and last to point to the nodes in a linked list. C. If a linked list is empty, first is null and last is null. D. If a linked list contains one element, first points to the node and last is null. E. last.next is always null.

B. MyLinkedList has the properties named first and last to point to the nodes in a linked list. C. If a linked list is empty, first is null and last is null. E. last.next is always null.

In the implementation of MyArrayList, which of the following are true? A. size never reduces. B. capacity never reduces. C. Inside MyArrayList, a regular array is used to store elements. D. size is not declared in MyArrayList, but declared in MyAbstractList as protected. E. If the current capacity equals to size, capacity is doubled when a new element is added to MyArrayList

B. capacity never reduces. C. Inside MyArrayList, a regular array is used to store elements. D. size is not declared in MyArrayList, but declared in MyAbstractList as protected. E. If the current capacity equals to size, capacity is doubled when a new element is added to MyArrayList

In the implementation of MyStack and MyQueue, which of the following are true? A. MyStack contains all the methods defined in MyArrayList. B. MyQueue contains all the methods defined in MyLinkedList. C. MyStack contains an array list for storing elements. D. MyQueue contains a linked list for storing elements.

C. MyStack contains an array list for storing elements. D. MyQueue contains a linked list for storing elements.

Suppose list1 is an MyArrayList and list2 is a MyLinkedList. Both contains 1 million double values. Analyze the following code: A: while (list1.size() > 0) list1.remove(size() - 1); B: while (list2.size() > 0) list2.remove(size() - 1);

Code fragment A runs as fast as code fragment B.

Suppose list1 is an MyArrayList and list2 is a MyLinkedList. Both contains 1 million double values. Analyze the following code: A: while (list1.size() > 0) list1.remove(0); B: while (list2.size() > 0) list2.remove(0);

Code fragment B runs faster than code fragment A.

is efficient in O(1) time for appending elements, for inserting an element at the beginning of the list.

LinkedList

Which data structure is appropriate to store patients in an emergency room?

Priority Queue

Implemented using a heap and the element with the highest priority is retrieved first.

PriorityQueue

Implemented using a linked list. It stores and retrieves the elements in a first-in and first-out fashion.

Queue

Which data structure is appropriate to store customers in a clinic for taking flu shots?

Queue

ArrayList is more efficient than LinkedList for the following operations:

Retrieve an element given the index.

Suppose the rule of the party is that the participants who arrive later will leave earlier. Which data structure is appropriate to store the participants?

Stack

is implemented using an array list. It stores and retrieves the elements in a last-in and first-out fashion.

Stack


Ensembles d'études connexes

Chapter 6: Introduction to Vectors

View Set

Chapter 11 - Performance Appraisals

View Set

Pharm 2 Exam 4 Practice Questions

View Set

Ch 11 health problems of the infant

View Set

Case 1 Study - IB Business Management

View Set

Fundamentals of Nursing Course Point Quiz- CH. 7

View Set

Chapter 13- Marketing: Helping Buyers Buy

View Set

Communication in a Connected World (Module 1)

View Set