Data Structures II (Stacks, Queues, & Vectors) Flashcards

1
Q

What is a Stack?

A

An abstract data type that uses first-in last-out ordering (FILO). That is to say that insertions and removals to/from a stack are in the top position only.

A good analogy is a stack of cafeteria trays. New trays are placed on top, and any time you want to remove a tray from the stack, you take it off the top.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the two primary operations of a stack class, and what do they do?

A

A stack class will have two primary operations:
push – adds an item onto the top of the stack
pop – removes the top item from the stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How are stacks commonly used?

A

Typical application areas include compilers, operating systems, handling of program memory (nested function calls)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a Queue?

A

An abstract data type that uses first-in first-out (FIFO) ordering to its functionality. Insertions occur at the “end” of the queue, and removals from the “front” of the queue.

An analogy of this concept could be waiting in line for a ride at an amusement park. Get in line at the end. First come, first serve.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the two primary operations of a queue and what do they do?

A

A queue class will have two primary operations:
enqueue – adds an item into the queue (i.e. at the back of the line)
dequeue – removes an item from the queue (i.e. from the front of the line).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How are queues commonly used?

A

Typical application areas include print job scheduling, operating systems (process scheduling).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a vector?

A

A vector is a specific implementation of the sequence/list abstract data type. It is a data structure that stores items of the same type and is based on storage in an array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the primary usage of a vector?

A

By encapsulating an array into a class (a vector class), we can use dynamic allocation to allow the internal array to be flexible in size and handle boundary issues of the array (error checking for out-of-bounds indices).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the main advantages and disadvantages of a vector?

A

Advantages: Random access - i.e. quick locating of data if the index is known.

Disadvantages: Inserts and Deletes are typically slow, since they may require shifting many elements to consecutive array slots

How well did you know this?
1
Not at all
2
3
4
5
Perfectly