Pseudocode for algorithms Flashcards

(10 cards)

1
Q

What is the pseudocode for finding the size of a stack?

A

size()
return top + 1

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

what is the pseudocode for checking if the stack is empty?

A

isEmpty()
if top < 0:
return True
else:
return False
endif

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

What is the pseudocode for checking the top item in a stack without removing it?

A

peek()
if isEmpty():
return error
else:
return stackname[top]
endif

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

What is the psuedocode for adding an item to a stack?

A

push(element)
top = top +1
stackname[top] = element

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

what is the pseudocode for removing an item off the stack?

A

pop()
if isEmpty():
return error
else:
toRemove = stackname[top]
stackname[top] = “ “
top = top - 1
return toRemove
endif

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

what is the pseudocode for checking the size of a queue?

A

size()
return back - front

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

what is the pseudocode for checking if a queue is empty?

A

isEmpty()
if front == back:
return True
else:
return False
endif

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

what is the pseudocode for returning the first item to enter a queue without removing it?

A

peek()
return queuename[front]

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

what is the pseudocode for adding an item into a queue?

A

enqueue(element)
queuename[back] = element
back = back + 1

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

what is the pseudocode for removing items from a queue?

A

dequeue()
if isEmpty():
return error
else:
toDequeue = queuename[front]
endif

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