Playing as a guest? to earn XP and track your progress.
๐งฉ Introduction to Problem Solving Quiz
๐งฉ Introduction to Problem Solving
What is problem solving in computing?
Typing code without planning
Buying a faster computer
Fixing hardware faults
Identifying a problem, developing a step-by-step solution and turning it into a working program
Problem solving means identifying a problem, developing a step-by-step solution and converting it into a working program.
In the building analogy, the algorithm is like the building's:
Blueprint
Bricks
Paint
Owner
The program is the building and the algorithm is its blueprint โ you plan before you build.
What is the correct order of the four steps of problem solving?
Testing โ Coding โ Analysing โ Algorithm
Analysing โ Developing an algorithm โ Coding โ Testing and debugging
Coding โ Analysing โ Testing โ Algorithm
Algorithm โ Analysing โ Testing โ Coding
The steps are Analyse โ Develop an algorithm โ Code โ Test & debug (the 'A-D-C-T' trick).
During 'Analysing the problem', a programmer identifies:
The final source code
The syntax errors
The inputs, the required output and any conditions or formulas
The colour scheme of the program
Analysis means understanding what is needed: inputs, outputs, processing/formulas and conditions.
For the problem 'Find the area of a rectangle', what are the inputs?
Area
Only the length
Perimeter
Length and breadth
The inputs are length (L) and breadth (B); the output is the area, and the formula is Area = L ร B.
What happens in the 'Testing and debugging' step?
The program is run with many different inputs to find and remove errors
The flowchart is drawn
The algorithm is first written
The problem is analysed
The program is run with different inputs (including unusual ones) to find and fix errors, then re-tested.
What is an algorithm?
A type of flowchart symbol
A finite sequence of clear, well-defined steps that solves a problem
A Python program
A computer's hardware
An algorithm is a finite sequence of clear, well-defined steps that produces the desired output for the given input.
The word 'algorithm' comes from the name of which mathematician?
George Boole
Euclid
al-Khwarizmi
Aryabhata
It comes from the 9th-century Persian mathematician Abu Ja'far Muhammad ibn Musa al-Khwarizmi.
Why is writing an algorithm before coding useful?
It makes the computer faster
It removes the need for testing
It is required by Python syntax
It gives a clear plan, and logic mistakes can be found early on paper
An algorithm gives a clear roadmap, saves time by catching logic errors early, is language independent and is easy to share.
An algorithm being 'language independent' means:
The same algorithm can be coded in Python, Java or C++
It needs no input
It cannot be translated
It can only be written in English
An algorithm is not tied to any language; it can be coded in any programming language.
Which set lists the characteristics of a good algorithm?
Speed, Colour, Size, Cost, Memory
Precision, Uniqueness, Finiteness, Input, Output
Sequence, Selection, Repetition, Input, Output
Syntax, Indentation, Comments, Loops, Output
The characteristics are Precision, Uniqueness, Finiteness, Input and Output ('PUFIO').
The instruction 'Add some sugar' violates which characteristic of a good algorithm?
Input
Output
Precision
Finiteness
Precision requires every step to be clearly and exactly stated; 'some' is vague.
The step 'Keep adding 1 to x' (with no stopping condition) violates:
Precision
Uniqueness
Input
Finiteness
Finiteness requires the algorithm to stop after a finite number of steps.
The characteristic that the result of each step depends only on the input and earlier steps is called:
Uniqueness
Finiteness
Precision
Output
Uniqueness: each step's result is uniquely defined by the input and the results of previous steps.
How many inputs and outputs must a good algorithm have?
Exactly one input and one output
Zero or more inputs and at least one output
Two inputs and two outputs
At least one input and zero outputs
An algorithm takes zero or more inputs and produces at least one output.
Which statement about algorithms and programs is correct?
Algorithms must use Python syntax
They are exactly the same
An algorithm is a step-by-step plan without language syntax; a program is that plan written in a programming language
A program is written before the algorithm
An algorithm is written in simple English-like steps; a program is the algorithm expressed in a language such as Python.
What are the two popular ways of representing an algorithm?
Python and Java
Compiler and interpreter
Truth table and K-map
Flowchart and pseudocode
An algorithm can be represented visually as a flowchart or in text as pseudocode.
What is a flowchart?
A visual representation of an algorithm using standard symbols connected by arrows
A program written in Python
A type of loop
A table of variable values
A flowchart is a pictorial representation of an algorithm, using standard symbols and arrows to show the flow of control.
Which flowchart symbol is used for Start and Stop?
Rectangle
Oval (terminal)
Diamond
Parallelogram
The oval or rounded rectangle is the terminal symbol for Start/Stop.
Which flowchart symbol is used for a decision (Yes/No)?
Parallelogram
Small circle
Diamond
Oval
A diamond represents a decision with Yes/No (True/False) branches.
Which flowchart symbol is used for input and output?
Diamond
Rectangle
Oval
Parallelogram
Input/Output steps, such as reading a value or printing a result, use a parallelogram.
Which flowchart symbol is used for a calculation such as sum = a + b?
Rectangle (process)
Diamond
Arrow
Parallelogram
Calculations and assignments use the rectangle (process) symbol.
What is the small circle used for in a flowchart?
Starting the flowchart
Connecting parts of a flowchart (connector)
Decisions
Printing output
A connector (small circle) joins parts of a flowchart, for example across pages.
A student used a rectangle to show 'INPUT num'. What is wrong?
It should use an oval
It should use a diamond
Input/output should use a parallelogram; the rectangle is for processes
Nothing is wrong
Input/Output uses a parallelogram; the rectangle is reserved for processing steps.
Which is a rule for drawing flowcharts?
Flow lines should cross as often as possible
A flowchart may have several Start symbols
Flow must go from bottom to top
A decision box has one entry and two exits (Yes/No)
Rules: one Start, at least one Stop, correct symbols, top-to-bottom/left-to-right flow, decision boxes with two exits, and no crossing lines.
What is pseudocode?
An informal, English-like way of writing an algorithm that does not follow any language's syntax
Code that has syntax errors
A Python library
Machine code
Pseudocode ('pseudo' means 'not real') resembles program code but follows no programming language's syntax.
Which keywords are commonly used for input in pseudocode?
PRINT, DISPLAY
INPUT, READ, GET
IF, WHILE
COMPUTE, SET
Input keywords are INPUT, READ and GET; output keywords are PRINT, DISPLAY and OUTPUT.
Which is a benefit of pseudocode?
It runs directly on the computer
It uses pictures instead of text
It lets the programmer focus on logic rather than language grammar
It cannot be changed once written
Pseudocode keeps the focus on logic, is easy to read and write, and converts easily to any language.
Which statement comparing flowcharts and pseudocode is correct?
Pseudocode takes more space
Flowcharts are easier to modify than pseudocode
Flowcharts are better for very large problems
Pseudocode is easier to modify; flowcharts may need to be redrawn
Pseudocode is compact and easy to edit and suits large problems; flowcharts are visual but harder to modify.
The flow of control means:
The order in which the steps are executed
The speed of the CPU
The number of variables used
The direction of the flowchart arrows only
Flow of control is the order in which steps are executed.
What are the three basic control structures of any algorithm?
Input, Process, Output
Sequence, Selection, Repetition
Start, Stop, Decision
Analyse, Code, Test
Every algorithm is built from sequence, selection (decision) and repetition (iteration).
In a sequence structure:
Steps repeat while a condition is True
A condition decides the path
Steps run one after another in the written order, none skipped or repeated
Steps run in random order
Sequence executes steps one after another in the order they are written.
What does this program print when the input is 100?
C = float(input()) F = C * 9 / 5 + 32 print(F)
212
180.0
132.0
212.0
100 ร 9 / 5 + 32 = 180.0 + 32 = 212.0 (a float because / is used).
Selection (decision making) is best compared to:
A fork in the road where you travel only one path
Running laps on a track
Following a straight road
Standing still
Selection checks a condition and chooses one of the paths, like a fork in the road.
In the even/odd algorithm, which condition identifies an even number?
num > 2
num MOD 2 == 0
num / 2 == 0
num MOD 2 == 1
A number is even if the remainder of num รท 2 is 0 (num % 2 == 0 in Python).
For the 'largest of three numbers' program with inputs 12, 45 and 30, what is printed?
30 is the largest
Nothing
45 is the largest
12 is the largest
a > b and a > c is False (12 < 45); then b > c (45 > 30) is True, so '45 is the largest' is printed.
Repetition (iteration) means:
Choosing between two paths
Executing each step only once
Stopping the program
Executing a set of steps again and again while a condition remains True
In repetition (looping), steps repeat as long as the condition stays True.
In the algorithm for the sum of the first N natural numbers, what must sum be initialised to?
0
1
N
-1
sum starts at 0; starting at 1 would be a logical error.
In the factorial algorithm, why must fact start at 1 and not 0?
Because 0 is not a number
Because anything multiplied by 0 is 0
Because Python does not allow 0
It makes no difference
Anything ร 0 = 0, so fact must be initialised to 1.
What is the output of the sum-of-N-natural-numbers program for N = 5?
5
20
15
10
1 + 2 + 3 + 4 + 5 = 15.
Dry run the factorial pseudocode for N = 4. What is printed?
10
12
4
24
fact = 1 ร 1 ร 2 ร 3 ร 4 = 24.
What is a dry run?
Executing an algorithm by hand, step by step, on paper to check it
Running a program with no input
Deleting unused variables
Running a program without electricity
A dry run executes the algorithm manually, recording variable values in a trace table.
In a dry run, variable values at each step are recorded in a:
Truth table
Trace table
Flowchart
Dictionary
A trace table records the values of variables as the algorithm is executed by hand.
Testing the sum algorithm with N = 0 or N = 1 is an example of testing with:
Random values
Normal values
Boundary values
Invalid values
Boundary values test the edges of valid input; N = 5 is normal, and N = -3 or 'abc' are invalid.
Using i < N instead of i <= N in the sum loop would cause:
A ZeroDivisionError
A syntax error
No change in the output
A logical error โ the last number would be missed
The loop would stop one step early and miss N, a logical error that a dry run can catch.
On what basis are two algorithms for the same problem compared?
Time complexity and space complexity
Their font size and colour
The programmer's name
The number of comments
Algorithms are compared by time complexity (number of steps/time) and space complexity (memory needed).
Space complexity measures:
The number of flowchart symbols
How much memory an algorithm needs while running
How long a program's name is
The speed of the internet
Space complexity is the memory an algorithm requires; time complexity is the number of steps/time it takes.
To check whether N = 101 is prime, how many divisions does the โN method need, compared with 99 for dividing by every number from 2 to N โ 1?
99
101
9
50
Dividing only by 2 to โ101 (about 10) needs 9 divisions, so it is much faster.
Why is it enough to test divisors only up to โN when checking whether N is prime?
Python cannot divide by larger numbers
โN is always a factor
Numbers above โN are always prime
If N has a factor larger than โN, it must also have one smaller than โN
Factors come in pairs; if one factor is larger than โN, its partner is smaller, so checking up to โN is enough.
What is coding?
Converting an algorithm into a program using a programming language
Drawing a flowchart
Testing with invalid input
Analysing a problem
Coding converts the algorithm into a program; the program written by the programmer is called the source code.
Which is a good coding practice?
Testing with only one input
Using meaningful variable names and adding comments
Avoiding indentation
Using names like tm instead of total_marks
Good practices include meaningful names, comments, proper indentation, and testing with normal, boundary and invalid inputs.
What is decomposition?
Converting code to machine language
Combining many programs into one file
Breaking a large, complex problem into smaller, simpler sub-problems
Deleting old programs
Decomposition splits a big problem into smaller sub-problems whose solutions are combined to solve the whole.
Which is NOT a benefit of decomposition?
Each part is easier to understand
Different people can work on different parts
Errors can be traced to one small part
The problem no longer needs testing
Decomposition makes problems easier to understand, supports teamwork, eases debugging and allows reuse; testing is still needed.
A student report card system decomposed into 'input marks', 'calculate percentage', 'decide grade' and 'print report' is an example of:
Decomposition
Iteration
Selection
Compilation
Breaking the system into smaller sub-tasks is decomposition.
Which algorithm correctly checks whether a person is eligible to vote (age 18 or above)?
IF age > 18 THEN PRINT "Eligible" ELSE PRINT "Not eligible"
IF age >= 18 THEN PRINT "Eligible" ELSE PRINT "Not eligible"
WHILE age >= 18 PRINT "Eligible"
IF age < 18 THEN PRINT "Eligible"
Age 18 itself is eligible, so the condition must be age >= 18; using > 18 would wrongly reject 18-year-olds.