Chapter 13 Linked Structures: Stacks

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

Node

A class that represents a single element in a linked structure

Linked structure

A data structure that used object reference variables to create links between objects

What are the advantages of using an LINKED implementation as opposed to an array implementation?

A linked implementation allocates space only as it is needed and has a theoretical limit on the size of the hardware.

Compare and contrast a linked list and an array.

A linked list has no capacity limitations, whereas an array does. However, arrays provide direct access to elements using indexes, whereas a linked list must be traversed one element at a time to reach a particular point in the list.

Doubly linked lists

A linked list in which each node has references to both the next node and the previous node in the list

Linked list

A linked structure in which one object refers to the next, creating a linear ordering

Sentinel node

A node at the front or end of a linked list that serves as a marker and does not represent an element in the list

What is the difference between a doubly linked list and a singly linked list?

A singly linked list maintains a reference to the first element in the list and then a next reference from each node to the following node in the list. A doubly linked list maintains two references: front and rear. Each node in the doubly linked list stores both a next and a previous reference.

Program stack

A stack of activation records used to keep track of method invocations during program execution

What are the advantages of using an ARRAY implementation as opposed to a linked implementation?

An array implementation uses less space per object since it only has to store the object and not an extra pointer. However, the array implementation will allocate much more space than it needs initially.

How do object references help us define data structures?

An object reference can be used as a link from one object to another. A group of linked objects can form a data structure, such as a linked list, on which a collection can be based.

Activation record

An object that represents a method invocation

What are the advantages of the java.util.Stack implementation of a stack?

Because the java.util.Stack implementation is an extension of the Vector class, it can keep track of the positions of elements in the stack using an index and thus does not require each node to store an additional pointer. This implementation also allocates space only as it is needed, like the linked implementation.

What do the LinkedStack<T> and ArrayStack<T> classes have in common?

Both the LinkedStack<T> and ArrayStack<T> classes implement the StackADT<T> interface. This means that they both represent a stack collection, providing the necessary operations needed to use a stack. Although they both have distinct approaches to managing the collection, they are functionally interchangeable from the user's point of view.

Why should a linked list node be separate from the element stored on the list?

It is unreasonable to assume that every object that we may want to put in a collection can be designed to cooperate with the collection implementation. Furthermore, the implementation details are supposed to be kept distinct from the user of the collection, including the elements that the user chooses to add to the collection.

What impact would the use of sentinel nodes or dummy nodes have on a doubly linked list implementation?

It would take two dummy records in a doubly linked list, one at the front and one at the rear, to eliminate the special cases when dealing with the first and last nodes.

What is the potential problem with the java.util.Stack implementation?

The java.util.Stack implementation is an extension of the Vector class and thus inherits a large number of operations that violate the basic assumptions of a stack.

What special case exists when managing linked lists?

The primary special case in linked-list processing occurs when dealing with the first element in the list. A special reference variable is maintained that specifies the first element in the list. If that element is deleted, or if a new element is added in front of it, the front reference must be carefully maintained.

What would be the TIME complexity of the push operation if we chose to push at the end of the list instead of at the front?

To push at the end of the list, we would have to traverse the lsit to reach the last element. This traversal would cause the time complexity to be O(n). An alternative would be to modify the solution to add a rear reference that always pointed to the last element in the list. This would help the time complexity for add but would have consequences if we try to remove the last element.


Conjuntos de estudio relacionados

Mendel and Inheritance Sapling Questions

View Set

Contemporary Management Chapter 1 & 2

View Set

Principles of Accounting Exam 1 (quiz 1 &2)

View Set

Unit 3 + 7 Art History MCQ, CA 3 & 7, Art History Unit 3 + 7

View Set

Business Finance Final - Chapters 12, 13, 14

View Set

Linear Pair and Vertical Angles Practice

View Set