Algorithm Concepts: Characteristics and Design
Master the art of creating clear, efficient instructions — the foundation of all programming!
What Exactly is an Algorithm?
The Definition: An algorithm is a sequence of precise, step-by-step instructions for solving a problem or performing a task. It's like a recipe — follow the steps in order, and you'll get the desired result!
The "Human Algorithm"
You use algorithms every day without realizing it!
- Tying shoelaces: A specific sequence of loops and knots
- Making tea: Boil water, add tea bag, pour water, wait, remove bag
- Finding a word in a dictionary: Open to section, scan page, repeat until found
Why Algorithms Matter in Programming
Before writing code, programmers must design the algorithm. If the algorithm is wrong, the code will be wrong. A good algorithm is:
- Precise: Each step is clear with no ambiguity
- Ordered: Steps happen in the right sequence
- Finite: It eventually reaches an end
- Correct: It actually solves the problem
Click the steps in the correct order to teach the robot to make a sandwich!
Algorithm
A step-by-step sequence of instructions to solve a problem
Precision
Clarity in instructions with no ambiguity
Procedure
Another name for a set of steps that accomplishes a task
Five Characteristics of a Good Algorithm (Objective 4)
Not all sets of instructions are good algorithms. A quality algorithm must have these five characteristics:
1. Finiteness
The algorithm must have a clear starting point and MUST eventually end. An infinite loop is not an algorithm!
2. Definiteness
Each step must be clear and unambiguous. "Add some sugar" is not definite — "Add 2 teaspoons" is!
3. Input
The algorithm should accept zero or more inputs (pieces of data to work with).
4. Output
It must produce at least one result (output) — otherwise, what's the point?
5. Effectiveness
Each step must be simple enough to be done manually with just a pen and paper.
Click each "algorithm" to identify which characteristic it's missing!
The Three Building Blocks (Control Structures)
All algorithms, no matter how complex, can be built using just three basic control structures:
1. Sequence
Instructions executed one after another in a linear path. This is the simplest structure — like reading a book from page 1 to page 10.
2. Selection (Decision)
Choosing a path based on a condition. Using IF-THEN-ELSE statements to make decisions.
IF Age >= 18 THEN
PRINT "You can vote"
ELSE
PRINT "Too young to vote"
3. Iteration (Repetition)
Repeating a set of instructions multiple times. Using FOR, WHILE, or REPEAT loops.
FOR Count = 1 TO 10 DO
PRINT Count
Drag each code snippet to the correct control structure!
Y = X + 5
PRINT Y
PRINT "Pass"
ELSE
PRINT "Fail"
PRINT i
END FOR
PRINT "A"
END IF
Total = Total + 1
Total = Total + 2
Count = Count + 1
END WHILE
Sequence
Steps executed in order, one after another
Selection
Making decisions based on conditions (IF-THEN-ELSE)
Iteration
Repeating steps using loops (FOR, WHILE)
Representing Algorithms: Pseudocode vs. Flowcharts
There are two main ways to represent algorithms visually:
Pseudocode
Definition: An English-like shorthand used to represent program logic. It's easier to write than a flowchart but harder to visualize.
- Uses programming-like keywords (IF, FOR, WHILE)
- Written in sentence case or uppercase
- Focuses on logic, not syntax
- Great for SBA documentation
Flowcharts
Definition: A graphical representation using standardized symbols to show the flow of execution.
- Uses shapes to represent different operations
- Easy to visualize and understand at a glance
- Better for complex decision-making
- Great for planning before coding
Common Flowchart Symbols
Start/Stop
Input/Output
Processing
Decision
Click each symbol to see what type of instruction belongs inside!
Begins or ends the algorithm
Receives data from user or displays results
Performs calculations or data operations
Tests a condition and branches based on result
Design Strategies: Top-Down vs. Bottom-Up
Top-Down Design
Starting with the main problem and breaking it into smaller sub-tasks. This is decomposition — exactly what you learned in the previous module!
- Level 0: The big picture goal (e.g., "Calculate Final Grade")
- Level 1: Major sub-tasks (e.g., "Input Scores", "Calculate Average", "Determine Grade")
- Level 2+: Even more detailed steps
Bottom-Up Design
Starting with individual small parts and combining them into a larger system. This is useful when reusable components already exist.
Why CSEC Favors Top-Down
Top-down design ensures the logic is sound before coding begins. You can verify that all requirements are met and that nothing is missing. It's easier to catch errors at the planning stage!
Click each level to expand it and see more detailed steps!
2. Compare and swap numbers
3. Display the sorted list
CSEC Practical: From Logic to Flowchart
The IPO Chart
Before creating a flowchart, start with an IPO (Input-Process-Output) Chart:
| Input | Process | Output |
|---|---|---|
| Test 1 Score Test 2 Score |
Average = (Test1 + Test2) / 2 IF Average >= 60 THEN Pass ELSE Fail |
Average Score Pass/Fail Status |
Expanding to a Flowchart
From the IPO chart, you can create a flowchart:
- Start Oval → "START"
- Input Parallelogram → "READ Test1, Test2"
- Process Rectangle → "Average = (Test1 + Test2) / 2"
- Decision Diamond → "Average >= 60?"
- Process Rectangles → "Pass" or "Fail"
- Output Parallelogram → "PRINT Average, Status"
- End Oval → "END"
After designing your algorithm, use a trace table to verify it works:
| Step | Test1 | Test2 | Average | Output |
|---|---|---|---|---|
| 1 | 85 | 90 | 87.5 | Pass |
Knowledge Check: The Algorithm Architect
Question 1: ATM PIN Check
You are designing an algorithm for an ATM. Which control structure is used to check if the PIN entered is correct?
Question 2: Algorithm Characteristics
Which of the following is NOT a characteristic of a well-defined algorithm?
Quick Reference: Control Structures
🔀 Selection
IF condition THEN... ELSE... — Used for decisions like PIN checks
🔄 Iteration
FOR/WHILE loops — Used when repeating actions (e.g., enter PIN 3 times)
📝 Sequence
Steps in order — Used for reading input, calculations, displaying results
Summary: Algorithm Fundamentals
Congratulations on completing this algorithm fundamentals module! You now understand how to create clear, effective instructions for solving problems.
Key Takeaways
What is an Algorithm?
A precise sequence of steps to solve a problem or complete a task
Five Characteristics
Finiteness, Definiteness, Input, Output, Effectiveness
Three Building Blocks
Sequence (order), Selection (decisions), Iteration (repetition)
Representation Methods
Pseudocode (text-based) and Flowcharts (symbols)
Design Strategy
Top-down decomposition breaks big problems into manageable parts
Flowchart Symbols
Oval (Start/Stop), Parallelogram (I/O), Rectangle (Process), Diamond (Decision)
🧠 Remember:
"A good algorithm is precise, ordered, finite, and effective!"
