Data Structures - Self-Review Questions 3

¡Supera tus tareas y exámenes ahora con Quizwiz!

True

An advantage of using a linked implementation as opposed to an array implementation is that a linked implementation allocates space only as it is needed.

EmptyCollectionException

What exception is thrown if the pop method is called on an empty stack?

dequeue

Which of the following is not an operation on a stack? 1) push 2) pop 3) peek 4) dequeue 5) all of the above are operations on a stack

True

The common feature between LinkedStack<T> and ArrayStack<T> classes is that both implement the Stack ADT

True. A stack is a LIFO structure, meaning that the last element that is inserted is the first element that is removed. LIFO stands for last-in-first-out.

A stack is a LIFO structure.

True. If there were no count variable in the linked implementation of stacks, the traversal would cause the time complexity to be O(n). An alternative would be to add a rear reference that should help with the add function but would have consequences if we try to remove the last element.

If there were no count variable in the linked implementation of stacks, the cost of traversing to know the size of the stack would cause the time complexity to be O(n).

False. In a linked implementation of a stack, a pushed element should be added to the front of the list. If the element is added to the end of the list, the pop operation would require linear time, because we would need to go through the entire element to get a pointer to the next-to-last element in the list.

In a linked implementation of a stack, a pushed element should be added to the end of the list.

False. The peek operation returns a reference to the element at the top of the stack.

The peek operation on a stack returns a reference to the element at the bottom of the stack.


Conjuntos de estudio relacionados

标准教程 HSK1 第一课 你好

View Set

advantages and disadvantage sole proprietorship

View Set

EXAM FX: Life and Health Stimulate Exam

View Set

Module 5: Government & the Economy

View Set

PSYCHOLOGY: Approaches- introspection

View Set

Pharm Chapter 3 Drug Action Across the Life Span

View Set

Radiographic Procedures III Final Review

View Set

Personal Finance Midterm Questions

View Set

Chapter 4: Harmony, Texture, Tonality, and Mode

View Set