AmbifulWorksheets
Cheat sheet
CBSE · Class 11 · Computer Science

Introduction to Problem Solving

Solving a problem step by step: analyse it, write an algorithm as a flowchart or pseudocode, code it, test it and debug it, tracing every step with values.

Key ideas

Remember

Flowchart symbolsoval: start or stop; parallelogram: input or output; rectangle: process; diamond: decision
Lines and joinsarrow: the direction of flow; small circle: a connector
Swap A and BSET temp = A, SET A = B, SET B = temp
Digits of NN MOD 10 is the last digit and N DIV 10 drops it; R = R × 10 + N MOD 10 reverses N
GCD (Euclid)WHILE B ≠ 0: R = A MOD B, A = B, B = R; then A is the GCD (48 and 18 → 6)
Prime check of Nup to N − 1: N − 2 divisions; up to √N: (whole part of √N) − 1 divisions
Counting a looplist the values I takes; the loop stops at the first value that fails the test

Watch out

Worked example

Trace this pseudocode.
 1 INPUT N (N = 10)
 2 SET S = 0
 3 SET I = 2
 4 WHILE I <= N
 5 SET S = S + I * I
 6 SET I = I + 3
 7 END WHILE
 8 PRINT S
(a) What does it print? (b) How many times does the loop run? (c) What is I when the loop stops?

Working: I: 2, 5, 8, then 11 > 10

Answer: (a) 93; (b) 3; (c) 11