0% found this document useful (0 votes)
12 views

Data Structures HW

The document outlines various data structures including stacks, queues, arrays, lists, tuples, and trees, along with their properties and differences. It includes questions about algorithms for addition and subtraction using a stack, operations on a queue, and the representation of a delivery network using a graph. Additionally, it discusses the implementation of tree structures in a computer game and the processes for adding and deleting nodes.

Uploaded by

Newappollo11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Data Structures HW

The document outlines various data structures including stacks, queues, arrays, lists, tuples, and trees, along with their properties and differences. It includes questions about algorithms for addition and subtraction using a stack, operations on a queue, and the representation of a delivery network using a graph. Additionally, it discusses the implementation of tree structures in a computer game and the processes for adding and deleting nodes.

Uploaded by

Newappollo11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

1(a) Sundip writes an algorithm to carry out addition and subtraction.

The algorithm will use an initially


empty stack with the identifier numbers and will take input from the user.

The action the algorithm takes depends on the value input by the user. These actions are listed in Fig.
2.

Fig. 2

A stack is one data structure that is available for Sundip to use. She could also use a queue, list,
linked list, array or tuple.

(i) Describe one difference between a stack and a queue.

[2]

(ii) Describe one difference between an array and a list.

© OCR 2024. You may photocopy this page. 1 of 10 Created in ExamBuilder


[2]

(iii) State how a tuple is different to a list.

[1]

(iv) Describe how the second item in a linked list would be accessed using pointer values.

[3]

(b)

(i) Complete the diagram to show the state of the stack after each value is entered into the algorithm.
The letters will complete an action stated in Fig. 2.

The state of the stack after the first value, 8, has been completed for you.

© OCR 2024. You may photocopy this page. 2 of 10 Created in ExamBuilder


[3]

(ii) Complete the following table to give the output from this algorithm when the following set of inputs
are entered by the user. The letters will complete an action stated in Fig. 2.

Input data (from left to right) Output

9 3 A E

10 5 A 8 S E

25 5 S 2 3 A S E

[3]

(iii) If the user enters 4 2 S A E , the algorithm will not work correctly.

Explain what problem this input data will cause and why the problem occurs.

[3]

© OCR 2024. You may photocopy this page. 3 of 10 Created in ExamBuilder


2 Describe how an array can be used to store and access data in a stack data structure.

[4]

© OCR 2024. You may photocopy this page. 4 of 10 Created in ExamBuilder


3 A programmer uses a queue data structure to store data.

(i) Tick one box that describes how a queue operates.

Last In First Out

First In First Out

[1]

(ii) The figure below shows a queue data structure that contains a list of names. Alex is at the front of
the queue.

Alex Kofi Ben Sundip Tom

The operations that can be used on the queue are:

• enqueue() – This will add data that is passed in as a parameter to the queue.
• dequeue() – This will return the first element in the queue.

Show the contents of the queue after these operations have been performed:

enqueue("Charlie")
dequeue()
enqueue("Ling")
dequeue()
enqueue("Sara")

[2]

© OCR 2024. You may photocopy this page. 5 of 10 Created in ExamBuilder


4(a) Fig. 5 shows a graph data structure representing a small section of a parcel delivery network. Each
node represents an address where deliveries need to be made. The edges show the possible routes
and distances between these deliveries.

Fig. 5

Give one reason why the graph is a visualisation of the problem.

[1]

(b)

(i) State one way a directed graph is different to an undirected graph.

[1]

(ii) State one way a graph data structure is different to a tree data structure.

[1]

© OCR 2024. You may photocopy this page. 6 of 10 Created in ExamBuilder


5 A bubble sort will sort an array of 50 integer values called numberArray.

State why the integer values are stored in an array instead of separate variables.

[1]

6(a) Kira is creating a computer game where the user can play against the computer.

In each turn, each character can make one move from a selection of possible moves.

Kira uses a tree data structure shown in Fig. 1 to identify the range of possible moves the computer
can make from starting position A. Each connection is a move, with each node representing the result
of the move.

Fig. 1

Kira could have used a graph data structure to represent the moves in her game.

© OCR 2024. You may photocopy this page. 7 of 10 Created in ExamBuilder


Give two similarities and two differences between a tree and a graph data structure.
Similarity 1

Similarity 2

Difference 1

Difference 2

[4]

© OCR 2024. You may photocopy this page. 8 of 10 Created in ExamBuilder


(b) Kira wants to make some changes to the data that is stored in the tree structure shown in Fig. 1.

(i) The move represented by node ‘E’ needs to be deleted.

Describe the steps an algorithm will follow to delete node ‘E’ from the tree.

[3]

(ii) The move represented by the node ‘K’ needs to be added. Node ‘K’ needs to be joined to node ‘G.’

Describe the steps the algorithm will follow to add node ‘K’ to the right of node ‘G’.

[3]

© OCR 2024. You may photocopy this page. 9 of 10 Created in ExamBuilder


(c) Kira wants the program to traverse the tree to evaluate the range of possible moves. She is
considering using a breadth-first traversal or a depth-first (post-order) traversal.

Show how a breadth-first traversal would traverse the tree shown in Fig. 1.

[4]

(d) State what type of pointers are used to store nodes I, F, J and H so they do not point to any other
nodes.

[1]

(e) State why the tree shown in Fig. 1 is not an example of a binary search tree.

[1]

END OF QUESTION PAPER

© OCR 2024. You may photocopy this page. 10 of 10 Created in ExamBuilder

Powered by TCPDF (www.tcpdf.org)

You might also like