QUESTION 2: Structured Questions (70 Marks]
• Answer all the questions in the provided booklet.
• The Question consists of 5 questions.
2.1 Consider the following data elements:
DSA, INP, BST, BCMS, DPG, PRG
By way of a diagram show how the above data can be stored in an array, conceptually. Your diagram
must clearly show the cells as well as the cell index.
[12 Marks]
2.2 Consider the following data elements: 23, 12, 10, 56, 8, by way of a diagram show how the above
data can be stored using a singly-linked list.
[12 Marks]
2.3 Study the code fragment below and answers the following questions.
mystery (marks[], size)
FOR (outerCounter=O to size-1)
lowestlndiex= outerCounter
FOR (innerCounter= outerCounter +1 to size-1)
IF(marks[innerCounter] < marks[lowestlndiex] )THEN
lowestlndiex= innerCounter
ENDFOR
ENDIF
ENDFOR
marks[outerCounter]=
marks[lowestlndiex]
END mystery()
a) What is the final output of the algorithm if an array, marks= {45, 75, 62, 18} is passed to
function mystery()?
[8 marks]
b} If the two (2) highlighted lines are added, what will be the output for the same array,
marks={45,75, 62,18}. Show state or content of array after each iteration of the outer loop.
[6 Marks]
mystery (marks[], size)
FOR (outerCounter=O to size-1)
lowestlndiex= outerCounter
FOR (innerCounter= outerCounter +1 to size-1)
IF(marks[innerCounter] < marks[lowestlndiex] )THEN
lowestlndiex= innerCounter
ENDIF
ENDFOR
temp= marks[outerCounter]
marks[ outerCounter ]= marks [lowestl ndiex]
marks[lowestlndiex]= temp
Page I 3