Save
Computer science OCR A Level
2.3.2 Algorithms for the main data structures
Save
Share
Learn
Content
Leaderboard
Share
Learn
Created by
Aanya Sinha
Visit profile
Cards (33)
What do
algorithms
and
data structures
do together
?
They
allow data to be manipulated effectively
View source
What type of data structure is a stack?
First in, last out (
FILO
)
View source
How is a stack typically implemented?
As an
array
with a single
pointer
View source
What is the purpose of the top pointer in a stack?
It tracks the top element of the stack
View source
Why is the top pointer initialized at -1?
To indicate that the
stack
is empty
View source
What does the size() function return in a stack?
The
number
of
elements
on
the
stack
View source
How is the size of the stack calculated in pseudocode?
Return
top
+ 1
View source
What does the isEmpty() function check in a stack?
If the
top pointer
is less than 0
View source
What does the peek() function do in a stack?
Returns
the
top
element
without
removing
it
View source
What should be checked before using peek() on a stack?
Whether the
stack
has
data
in it
View source
How is an element added to a stack?
By updating the
top pointer
and inserting the element
View source
What happens during the pop() operation in a stack?
The
top
element
is
removed
and
returned
View source
What must be checked before performing a pop() operation?
That the
stack
isn’t empty
View source
What is the result of the peek() operation after pushing 1, 5, and 4 onto the stack?
4
View source
What does the isEmpty() function return after pushing elements onto the stack?
False
View source
What happens when trying to push onto a full stack?
An
error
is returned
View source
What is the final output of the stack operations performed?
4
, 4, False,
2
, 5
View source
What type of data structure is a queue?
First in, first out (FIFO)
View source
How is a queue typically represented?
As an
array
with two
pointers
View source
What do the front and back pointers in a queue represent?
Front holds the first element,
back
the next space
View source
How is the size of a queue calculated?
By subtracting
front
from
back
View source
What does the isEmpty() function check in a queue?
If
front
and
back
point to the same position
View source
What does the peek() function do in a queue?
Returns
the
front
element
without
removing
it
View source
How is an element added to a queue?
By placing it at the
back
pointer's position
View source
What happens during the dequeue() operation in a queue?
The
front
element is removed and returned
View source
What must be checked before performing a dequeue() operation?
That
the
queue
isn’t
empty
View source
What is the result of the dequeue() operation on the queue?
Alex
View source
What is the size of the queue after enqueuing Julia?
5
View source
What does the peek() operation return after enqueuing Julia?
Rajiv
View source
What is the final output of the queue operations performed?
Alex
, 5,
Rajiv
, 5, Rajiv,
False
View source
What are the main operations associated with stacks?
size()
isEmpty()
peek()
push(element)
pop()
View source
What are the main operations associated with queues?
size()
isEmpty()
peek()
enqueue(element)
dequeue()
View source
Compare the structure and operations of stacks and queues.
Stacks:
FILO
structure
Single pointer (top)
Operations: push, pop, peek
Queues:
FIFO
structure
Two pointers (front, back)
Operations: enqueue, dequeue, peek
View source