Algorithms for the Main Data Structures (OCR A Level Computer Science)

Exam Questions

11 mins3 questions
12 marks

A computer uses a stack data structure, implemented using an array, to store numbers entered by the user.

The array is zero based and has 100 locations

The main program initialises a new object of type stack with the identifier mathsStack.

Write pseudocode or program code to declare the object.

Did this page help you?

24 marks

Lucas writes a program that makes use of a circular queue. The queue stores the data entered into the program. An array is used to represent the queue.

The program needs two pointers to access and manipulate the data in the queue.

State the purpose of the two pointers and give an appropriate identifier for each.

Did this page help you?

35 marks

A program stores data in a linked list.

The current contents of the linked list are shown in Fig. 3, along with the linked list pointers.

Diagram of a linked list with data. Head pointer at location 1, free list pointer at location 4. Data includes colours like "blue" and "red".

The function findNode will search the linked list and return either the position of the node that contains the data item, or -1 if the data item is not found.

The data held in a node at location x can be accessed with linkedList[x].data. The pointer of the node at location x can be accessed with linkedList[x].pointer.

For example, using the linked list shown in Fig. 3: linkedList[2].data returns green.
linkedList[2].pointer returns 8.

Complete the function, using pseudocode or program code.

function findNode(toFind, headPointer, linkedList)

  currentNode = ………………………………

  while(currentNode != ………………………………)

   if linkedList[currentNode]. ……………………………… == toFind 

    return currentNode

  else

   currentNode = linkedList[………………………………].pointer

  endif

 endwhile

 return ………………………………

 endfunction

Did this page help you?