Stacks and Queues Flashcards

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

stacks

what is a stack

A

container of objects that are inserted and removed acording to the LIFO principle

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

stacks

what is the main principle of a stack

A

Last in First Out
(LIFO)

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

stacks

elements can only be added and removed from ther stack at the …

A

top

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

stacks

a stack is an …… data type

A

abstract

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

stacks

name the 5 functions u can do top a stack and what they do

A
  • push - adds item to top of stack
  • pop - removes item from the top of stack
  • top - returns top element (doesnt remove)
  • test for empty - prevent underflow
  • test for full - prevent underflow
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

stacks

example of the use of a stack

A

undo button

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

stacks

when is an array implementatio for a stack used

A

when the size is predictable

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

stacks

what are the two ways a stack can be implemented

A
  • array
  • linked list
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

stacks

what are the disadvantages of an array implementation for a stack

A
  • limited size
  • empty entries waste space
  • can be stack overflow
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

stacks

what are the disadvantages and advantages of an linked list implementation for a stack

A
  • -space used by pointers
  • +no stack overflow
  • +unlimited size
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is the principle of a queue

A

the first item inserted is the first to be removed
(FIFO)

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

queues

what are the two pointers in a queue called and what do they do

A
  • front - keeps track of first element
  • rear - keeps track of the last element
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

queues

how do you add an element to a queue

A

enqueue

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

queues

how do u remove an element from a queue

A

dequeue

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

queues

write an algorithm to show how a data item is added into a queue

take into account possibility of it being full

A
  • declare max size
  • calculate number of elements by size = tail - head
  • check if size is less than max size
  • if yes, add item to queue
  • if no, error msg saying queue is full
How well did you know this?
1
Not at all
2
3
4
5
Perfectly