Signed up recently but had issues with the confirmation email?
Click Forgot password and follow the reset steps. You can choose the same password you used when you signed up. This should then provide access.
Remember to check Spam and Junk. The email will be from auth@progressbytes.co.uk.
How to create, traverse, add data to and remove data from the data structures mentioned above. (NB this can be either using arrays and procedural programming or an object-oriented approach)
1.4.2 Data Structures
Practise exam questionsData Structures — Note 3 of 3
Candidates should have experience of implementing these structures in a variety of contexts, for example through a procedural program, through a different data structure and through an object-oriented approach. Candidates need to be able to read, trace and write code to implement features of these data structures. (Again we would recommend a general understanding backed up with practice implementing them, rather than trying to memorise code patterns).
You need to be able to read, trace and write code that creates and manipulates linked lists, stacks, queues, trees, graphs and hash tables. This can be done procedurally using arrays and pointers, or using an object-oriented approach.
MOD.adj[a,b] holds the edge from vertex a to vertex b: 1 or 0 if unweighted, or the weight, with a no-edge value the question states (e.g. -1 or ∞). Add an edge by setting the cell; remove it by resetting the cell to the no-edge value. In an undirected graph, change BOTH adj[a,b] and adj[b,a]. To add a vertex to a full static array, copy it into a larger array, keeping every edge, and fill the new row and column with the no-edge value.array stack[10]
top = -1
procedure push(item)
if top == 9 then
print("Stack overflow")
else
top = top + 1
stack[top] = item
endif
endprocedure
function pop()
if top == -1 then
print("Stack underflow")
return null
else
item = stack[top]
top = top - 1
return item
endif
endfunctionSIZE = 5
queue = [None] * SIZE
front, rear, count = 0, -1, 0
def enqueue(item):
global rear, count
if count == SIZE:
print("Queue full")
return
rear = (rear + 1) % SIZE # wrap around
queue[rear] = item
count += 1
def dequeue():
global front, count
if count == 0:
print("Queue empty")
return None
item = queue[front]
front = (front + 1) % SIZE # wrap around
count -= 1
return itemclass Node:
def __init__(self, data):
self.data = data
self.next = None
def traverse(start):
current = start
while current is not None:
print(current.data)
current = current.next
def insert_after(node, data):
new_node = Node(data)
new_node.next = node.next # new node points to the old next
node.next = new_node # previous node points to the new node// Undirected, weighted graph: vertices A to D are indexes 0 to 3
// -1 means no edge
array adj[4,4]
for r = 0 to 3
for c = 0 to 3
adj[r,c] = -1
next c
next r
procedure addEdge(a, b, weight)
adj[a,b] = weight
adj[b,a] = weight // undirected: both directions
endprocedure
procedure removeEdge(a, b)
adj[a,b] = -1
adj[b,a] = -1
endprocedure
procedure printNeighbours(v)
for c = 0 to 3
if adj[v,c] != -1 then
print(c)
endif
next c
endprocedure
addEdge(1, 3, 4) // add B-D with weight 4return last: nothing after it runs.top == 9 for stack[10]. A circular queue wraps round, so it needs a count, as in the queue code here.Past exam questions
Ready to test yourself?
Practise 1.4.2 questions