Data structure algorithms (2.3.1 e) Flashcards

(8 cards)

1
Q

Stack and queue traveral

A

cannot be traversed
can only peek

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

Removing data - data structure

A

when removing data from a structure the data is never deleted
after pointers are updated the memory location is flagged and available
the next time data is added the previous data is overwritten

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

Stack pop algorithm

A

check if the stack is empty if so return an error/-1/false and stop (stack underflow)
if the stack is not empty return top item (use a next pointer to find it if necessary)
if top is first available space change top pointer to point where the top pointer was
if top is top item change top pointer to top items next pointer
top is to
if top is top item flag previous top items memory location as available/next

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

Stack push algorithm

A

check if the stack is full if it is return an error/-1/false (stack overflow)
if the stack is not full and if top is first empty space then store data in top pointer location with a next pointer indicating its previous item in the queue (null if this is the first item) and update top pointer to next available space
if the stack is not full and if top is top item then find next available location then store data there with a next pointer indicating previous item in the queue (null if this is the first item) and update the top pointer to this location

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

Queue dequeue algorithm

A

check if the queue is empty if so return error/-1/false and stop (queue underflow)
if not empty return the data at the top of the front pointer
set front pointer to the nodes next pointer

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

Queue enqueue algorithm

A

check if the queue is full if so return error/-1/false and stop (queue overflow)
if queue is not empty store data at location of the end pointer
set next pointer to previous item]set end pointer to next available location

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

Using arrays

A

procedural
mutable and static
stored in contiguous data
can use in built indexing as pointers
pointers will be variables which store integers which reference indexes of the arrays
define functions for pop push enqueue dequeue

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

What do we pass into the functions as parameters and how?

A

by Ref - memory location during the procedure/function the original value will change
by Val - a new local copy of variable is created changes are made using this val/variable and the original memory location is unchangeable - new variables = more memory required

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