Unit: Problem Solving & Algorithm Development
Problem-solving is the process of finding solutions to difficult or complex issues. In Information Technology, this involves a systematic approach to breaking down a task into steps that a computer can execute.
1. The Algorithm
An algorithm is a sequence of precise, step-by-step instructions for solving a problem or performing a task. It is the “blueprint” of a program.
- Finiteness: It must eventually end.
- Definiteness: Each step must be clearly defined and unambiguous.
- Input/Output: It takes zero or more inputs and produces at least one output.
- Efficiency: It should solve the problem using the least amount of resources (time/memory).
2. Flowcharts
A flowchart is a pictorial or graphical representation of an algorithm. It uses standard symbols connected by arrows (flow lines) to show the sequence of operations.
Common Flowchart Symbols:
Symbol
Name
Function
Oval
Terminal
Indicates the Start or Stop of the process.
Parallelogram
Input / Output
Represents data being entered into or exiting the system.
Rectangle
Process
Represents an action or a calculation (e.g., x = a + b).
Diamond
Decision
Represents a branching point (Yes/No or True/False).
Arrows
Flow Lines
Shows the direction of the process flow.
3. Pseudocode
Pseudocode (fake code) is a detailed yet readable description of what a computer program or algorithm must do. It uses the structural conventions of programming languages but is intended for human reading rather than machine reading.
Key Structures in Pseudocode:
- Assignment: Using arrows or keywords to give variables values (e.g., Set total to 0).
- Selection (IF-THEN-ELSE): Used when a choice needs to be made.
- Iteration (Loops): Used for repeating steps (e.g., FOR, WHILE, REPEAT-UNTIL).
4. Worked Example: Calculating Average
Problem: Design a solution that accepts three numbers, calculates the average, and displays the result.
The Pseudocode:
START
PRINT “Enter three numbers:”
INPUT num1, num2, num3
average = (num1 + num2 + num3) / 3
PRINT “The average is”, average
STOP
The Flowchart Logic:
- Start (Oval)
- Input num1, num2, num3 (Parallelogram)
- Sum = num1 + num2 + num3 (Rectangle)
- Avg = Sum / 3 (Rectangle)
- Output Avg (Parallelogram)
- Stop (Oval)
5. Control Structures
To solve complex problems, algorithms use three main structures:
- Sequence: Steps are followed in a strict top-to-bottom order.
- Selection: Making a decision based on a condition (e.g., “If mark > 50, then Pass”).
- Repetition (Looping): Repeating a set of instructions until a condition is met (e.g., “Keep asking for a password until it is correct”).
1. Simple Addition
Goal: Input two numbers and display their sum.
Plaintext
BEGIN
PROMPT “Enter first number: “
INPUT num1
PROMPT “Enter second number: “
INPUT num2
sum = num1 + num2
PRINT “The sum is: “, sum
END
2. Checking for Voting Eligibility
Goal: Determine if a person is old enough to vote (18+).
Plaintext
BEGIN
PRINT “Enter your age: “
INPUT age
IF age >= 18 THEN
PRINT “You are eligible to vote.”
ELSE
PRINT “You are too young to vote.”
ENDIF
END
3. Temperature Converter (Celsius to Fahrenheit)
Goal: Convert a temperature using the formula $F = (C \times 1.8) + 32$.
Plaintext
BEGIN
PRINT “Enter temperature in Celsius: “
INPUT celsius
fahrenheit = (celsius * 1.8) + 32
PRINT “Temperature in Fahrenheit: “, fahrenheit
END
4. Grade Classifier
Goal: Assign a letter grade based on a numerical score.
Plaintext
BEGIN
INPUT score
IF score >= 80 THEN
grade = “A”
ELSE IF score >= 70 THEN
grade = “B”
ELSE IF score >= 50 THEN
grade = “C”
ELSE
grade = “F”
ENDIF
PRINT “Your grade is: “, grade
END
5. Count-Controlled Loop (For Loop)
Goal: Print the “Times Table” for the number 5 up to 12.
Plaintext
BEGIN
FOR i = 1 TO 12 DO
product = 5 * i
PRINT “5 x “, i, ” = “, product
ENDFOR
END
6. Sentinel-Controlled Loop (While Loop)
Goal: Continuously ask for numbers and add them until the user enters -1.
Plaintext
BEGIN
total = 0
INPUT num
WHILE num != -1 DO
total = total + num
PRINT “Enter next number or -1 to quit: “
INPUT num
ENDWHILE
PRINT “The final total is: “, total
END
7. Finding the Largest of Two Numbers
Goal: Compare two values and output the higher one.
Plaintext
BEGIN
INPUT a, b
IF a > b THEN
PRINT a, ” is the largest.”
ELSE IF b > a THEN
PRINT b, ” is the largest.”
ELSE
PRINT “The numbers are equal.”
ENDIF
END
8. Even or Odd Checker
Goal: Determine if a number is even or odd using the Modulo (%) operator.
Plaintext
BEGIN
PRINT “Enter a number: “
INPUT n
IF n % 2 == 0 THEN
PRINT n, ” is Even.”
ELSE
PRINT n, ” is Odd.”
ENDIF
END
9. Area of a Circle
Goal: Calculate area using $Area = \pi r^2$.
Plaintext
BEGIN
PI = 3.142
PRINT “Enter radius: “
INPUT radius
area = PI * (radius * radius)
PRINT “The area is: “, area
END
10. Simple Login Validation
Goal: Check if a user entered the correct secret password.
Plaintext
BEGIN
CorrectPass = “Jamaica2026”
PRINT “Enter Password: “
INPUT UserPass
IF UserPass == CorrectPass THEN
PRINT “Access Granted”
ELSE
PRINT “Access Denied”
ENDIF
END