Stacks and Queues Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is a queue?

A

A queue is a group of items all of the same type where items are added to the back of the queue and removed from the front.

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

What is the principle of a Queue

A

FIFO

first-in first-out

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

What are the methods of a Queue and what do they do?

A
add(x) = adds item x to the queue
remove() = removes and returns front item
peek() = returns the front item with no remove
size() = returns the # of the items in the queue
isEmpty() = checks to see if the queue is empty
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the methods of a Priority Queue and what do they do?

A
add(x) = adds item x to the pQueue
remove() = removes and returns min priority item 
peek() = returns the min item with no remove
size() = returns the # of items in the pQueue
isEmpty() = checks to see if the pQueue is empty
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference between the pQueue and queue?

A

pQueue orders them based on the ASCII table while queue does not order at all.

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

What is a Stack

A

A stack is a group of items all of the same type where items are added to the top of the stack and removed from the top.

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

What is the principle of Stacks?

A

LIFO

last-in first-out

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

What are the methods of a Stack and what do they do?

A
push(x) = adds item x to the stack
add(x) = adds item x to the stack
pop() = removes and returns an item
peek() = returns the top item with no remove
size() = returns the # of items in the stack
isEmpty() = checks to see if the stack is empty
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the packages needed to call the data structures?

A

Queue = import java.util.Queue;

Stack = import java.util.Stack;

Both = import java.util.*;

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

How does the principles work in data Structures.

A

As an example, the last-in first-in principle means that “the last element added is the first to be taken out”.

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