User interface language: English | Español

Date May 2018 Marks available 3 Reference code 18M.2.HL.TZ0.19
Level HL Paper 2 Time zone no time zone
Command term Explain Question number 19 Adapted from N/A

Question

Consider the following recursive method.

public void recursionEx(int x)
{
  if(x != 0)
  {
    System.out.println(x);
    recursionEx(x - 1);
    System.out.println(x);
  }
}

Identify two essential features of a recursive algorithm.

[2]
a.

Copy and complete the following table to show the output when the method is called by: recursionEx(3);

[4]
b.

Explain what would happen if the method was called by recursionEx(-3).

[3]
c.

Identify three features which should be included in either program code or UML diagrams to help programmers understand and modify programs in the future.

[3]
d.

Markscheme

The method calls itself;
With a changing parameter;
There is a base (terminating) case;

a.

Award marks as follows:
Outputting 6 values;
Correct parameter list
First 3 output numbers correct;
Last 3 output numbers correct;

b.

An infinite loop / program will never end/terminate;
Will eventually cause the program to crash;
As it runs out of memory for the parameters stored / Stack overflow;
As the base case is never reached;

c.

Comments can be added;
Use of meaningful names;
Correct indentation;
Relationships/dependencies shown between class (UML) diagrams;

d.

Examiners report

[N/A]
a.
[N/A]
b.
[N/A]
c.
[N/A]
d.

Syllabus sections

Option D: Object-oriented programming » D.4 Advanced program development
Show 33 related questions
Option D: Object-oriented programming

View options