ISC · Computer Science Paper 2 (Practical)
How to write the algorithm
The algorithm is the first thing you write in the practical, and the part students find hardest. Here is how it is marked, the rules of the step-wise style, and a worked example. Every one of the 53 solved questions on this site now has its own algorithm.
Where the algorithm fits
The practical paper lasts three hours, plus 15 minutes of reading time. You choose one of three problems. The first part is a planning session of up to 90 minutes, in which you write, on paper, the algorithm and then the Java program. Only after that do you move to the computer to type the program, print it and run it on the sample data.
Paper 2 carries 30 marks. Half come from your year's practical work; the other 15 come from the examination itself:
| Part | Marks |
|---|---|
| Algorithm | 3 |
| Java program with documentation (comments and meaningful names) | 7 |
| Printout (hard copy) of the program | 2 |
| Output: running the program on the given sample data | 3 |
| Total | 15 |
What earns the 3 marks
The question paper asks for an algorithm expressed clearly in a standard form: pseudocode or numbered steps. In practice, an algorithm scores well when it gets two things right:
- The method: is it sound, and will it actually solve the problem?
- The writing: is it complete, clear, in one standard form, and does it match your program?
The algorithm also matters beyond these 3 marks. The paper asks for a program that follows the algorithm, and the program you finally type and print should be the one you planned. So plan the program you will actually write, and write the algorithm for that program.
The step-wise style: rules that earn the marks
The paper accepts pseudocode or numbered steps. Most students find numbered steps easier, and that is the style used on this site.
- Begin with "Step 1: Start" and end with a "Stop" step. Number every step.
- Input first, then check it. Practical questions almost always ask you to check that the size, range or format of the input is valid. Make that a step of its own, write the exact error message, and send the algorithm to the Stop step.
- One action per step. When a step has parts, number them as sub-steps: 5.1, 5.2, …
- Write loops and decisions plainly. "For i = 0 to n − 1, repeat Steps 5 to 7." "While temp > 0, …" "If sum = n, display … ; otherwise …".
- Use the names from your program for variables, arrays and methods, so the examiner can match the two. Give each method you write (such as
isPrime(n)) its own short algorithm. - Say how, not just what. "Check whether n is a Kaprekar number" earns little. Show how the check is done.
- Show the output exactly as the question asks, including headings and messages.
Common mistakes
- Writing Java statements (
System.out.println,charAt(),for (int i = 0; …)) instead of steps. Simple arithmetic such as n % 10 is fine. - Mixing pseudocode and numbered steps in the same algorithm.
- Leaving out the input checks or the error messages.
- Vague steps ("process the matrix", "find the answer") that could describe any program.
- Writing a different method in the algorithm from the one in the program.
- Forgetting the methods: if your program has
isPrime(), the algorithm needs it too.
Worked example: Kaprekar Number (ISC 2010, Question 2)
The question asks for all Kaprekar numbers between two limits p and q (both below 5000), with their frequency. Read the full question and program.
An algorithm that loses marks:
Step 1: Input p and q. Step 2: Check each number from p to q to see if it is a Kaprekar number. Step 3: Print the Kaprekar numbers and their frequency.
It doesn't check the input, doesn't say how a Kaprekar number is recognised, and doesn't match the program's methods. Compare it with the full algorithm:
An algorithm that earns them:
- Step 1: Start.
- Step 2: Input p and q. If p or q is not positive, or not less than 5000, or p ≥ q, display "INVALID INPUT" and go to Step 7.
- Step 3: Set frequency = 0 and list = "".
- Step 4: For i = p to q, if isKaprekarNumber(i) is true, increase frequency by 1 and join i followed by ", " to list.
- Step 5: Remove the last ", " from list.
- Step 6: Display "THE KAPREKAR NUMBERS ARE:-", list, and "FREQUENCY OF KAPREKAR NUMBERS IS:" followed by frequency.
- Step 7: Stop.
isKaprekarNumber(n)
- Step 1: square = n × n.
- Step 2: divisor = 1. For every digit of n, multiply divisor by 10. (If n has d digits, divisor = 10^d.)
- Step 3: right = square % divisor (the right-hand piece with d digits) and left = square / divisor (the remaining left-hand piece).
- Step 4: Return true if left + right = n, otherwise false.
What the questions usually look like
Going by past papers, the three questions usually come from these areas:
- String manipulation, including encryption and decryption
- One-dimensional arrays
- Two-dimensional arrays
- Number, date and time logic
Usually each question sticks to one area, though one may combine two (for example, numbers stored in an array, as in the 2020 octal matrix). Many are set in everyday situations, such as cartons, quiz scores or banners, and almost all expect you to check the validity of the input and to print the output neatly. Practise the matching topics: strings, arrays and matrices, number programs and date programs.
Before the planning session ends
- Every step is numbered, and the algorithm starts and stops.
- Every input is checked, with the error message the question asks for.
- Every method in your program has its own short algorithm.
- The output steps match the format in the question.
- You have traced the algorithm by hand with the sample input and got the sample output.
Watch: how to write an algorithm for the ISC practical
Plays from YouTube (privacy-enhanced mode) when you click.
All 53 questions, with algorithms and programs
Every ISC practical question from 2004 to 2021, each with a step-wise algorithm, a complete Java program and a video.