Preskoči na glavni sadržaj
Prijava
Sign up for FREE
arrow_back
Biblioteka

A2 - CS - End of Unit 19 test

star
star
star
star
star
Posljednje ažuriranje about 1 year ago
9

Answer all the questions.

7
5
5
4
2
6
7
5
5
Pitanje 1
1.
Pitanje 2
2.

Joseph is taking a toy apart. Each time he removes an item from the toy, he writes the name of the item at the bottom of a paper list. When he rebuilds the toy, he puts the items back together working from the bottom of the list.

Joseph writes a computer program to create the list using a stack, Parts.

(a) Describe a stack structure. [1]

(i) Describe the purpose of the variable StackPointer. [1]

Use the table below to show the contents of the stack, Parts, and its pointer after the following code is run. [3]

POP()

POP()

PUSH("Light 1")

PUSH("Light 2")

PUSH("Wheel 1")

POP()

POP()

Pitanje 3
3.
Pitanje 4
4.
Pitanje 5
5.

The recursive algorithm for the Calculate() function is defined as follows:

(i) State what is meant by a recursive algorithm. [1]

(ii) State the line number in Calculate() where the recursive call takes place. [1]

Pitanje 6
6.

The function in Q5 is called with Calculate(3).

Dry run the function and complete the trace table below. State the final value returned. Show your working. [6]

Pitanje 7
7.

A recursive algorithm within a subroutine can be replaced with an iterative algorithm.

(i) Describe one problem that can occur when running a subroutine that has a recursive algorithm. [2]

(ii) Rewrite the Calculate() function (of above question) in pseudocode, using an iterative algorithm. [5]

Pitanje 8
8.

A linked list abstract data type (ADT) is created. This is implemented as an array of records. The records are of type ListElement.

An example of a record of ListElement is shown in the following table.

(i) Use pseudocode to write a definition for the record type, ListElement. [3]

(ii) Use pseudocode to write an array declaration to reserve space for only 15 nodes of type ListElement in an array, CountryList. The lower bound element is 1. [2]

Pitanje 9
9.