Algorithm Concepts: Characteristics and Design

Master the art of creating clear, efficient instructions — the foundation of all programming!

1

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
The Robot Sandwich Maker

Click the steps in the correct order to teach the robot to make a sandwich!

🤖
🤖: "I'm ready to make a sandwich! Give me instructions."
1 Put jam on bread
2 Open the jar of jam
3 Get bread from the bag
4 Close the jam jar

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

2

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.

The Algorithm Audit

Click each "algorithm" to identify which characteristic it's missing!

WHILE True DO
PRINT "Hello"
END WHILE
💡 Hint: This runs forever!
Finiteness Violation: This algorithm never ends! It will print "Hello" forever because True is always true.
Step 1: Add some flour
Step 2: Mix until it "looks right"
Step 3: Bake until done
💡 Hint: What does "looks right" mean?
Definiteness Violation: "Mix until it looks right" and "Bake until done" are ambiguous. How much is "some"? When is it "right"? When is it "done"?
Step 1: Calculate all prime numbers
Step 2: Store them in order
💡 Hint: Can you actually do this manually?
Effectiveness Violation: Calculating ALL prime numbers is impossible because there are infinitely many! Each step must be practically doable.
3

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

Structure Matcher

Drag each code snippet to the correct control structure!

READ X
Y = X + 5
PRINT Y
IF Score > 50 THEN
PRINT "Pass"
ELSE
PRINT "Fail"
FOR i = 1 TO 100
PRINT i
END FOR
IF Grade >= 90 THEN
PRINT "A"
END IF
SET Total = 0
Total = Total + 1
Total = Total + 2
WHILE Count < 10
Count = Count + 1
END WHILE
📝 Sequence
🔀 Selection
🔄 Iteration

Sequence

Steps executed in order, one after another

Selection

Making decisions based on conditions (IF-THEN-ELSE)

Iteration

Repeating steps using loops (FOR, WHILE)

4

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

🔲
Oval

Start/Stop

📥
Parallelogram

Input/Output

📦
Rectangle

Processing

💠
Diamond

Decision

The Symbol Sandbox

Click each symbol to see what type of instruction belongs inside!

🔲
Start/Stop
📥
Input/Output
📦
Process
💠
Decision
🔲 Start/Stop (Terminator)

Begins or ends the algorithm

START / END
📥 Input/Output

Receives data from user or displays results

READ Name / PRINT "Hello"
📦 Processing

Performs calculations or data operations

Total = Price + Tax
💠 Decision (Diamond)

Tests a condition and branches based on result

IF Score > 50 THEN...
5

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!

The Stepwise Refiner

Click each level to expand it and see more detailed steps!

LEVEL 0 - The Goal
Sort a list of numbers in ascending order
Click to see Level 1...
LEVEL 1 - Main Sub-Tasks
1. Get the numbers from the user
2. Compare and swap numbers
3. Display the sorted list
1.1 READ N (number of items)
1.2 FOR i = 1 TO N
1.3   READ numbers[i]
2.1 FOR i = 1 TO N-1
2.2   FOR j = 1 TO N-i
2.3     IF numbers[j] > numbers[j+1] THEN
2.4       SWAP numbers[j], numbers[j+1]
3.1 FOR i = 1 TO N
3.2   PRINT numbers[i]
LEVEL 2 - Detailed Pseudocode
Expanded detailed instructions ready for coding
INPUT: N = 5, numbers = [3, 1, 4, 1, 5]
OUTPUT: [1, 1, 3, 4, 5]
← This is bubble sort algorithm!
6

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:

  1. Start Oval → "START"
  2. Input Parallelogram → "READ Test1, Test2"
  3. Process Rectangle → "Average = (Test1 + Test2) / 2"
  4. Decision Diamond → "Average >= 60?"
  5. Process Rectangles → "Pass" or "Fail"
  6. Output Parallelogram → "PRINT Average, Status"
  7. End Oval → "END"
📋 Trace Table Preview

After designing your algorithm, use a trace table to verify it works:

Step Test1 Test2 Average Output
1 85 90 87.5 Pass
7

Knowledge Check: The Algorithm Architect

Logic Challenge

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?

A Sequence — executing steps in order
B Selection — checking IF PIN matches
C Iteration — repeating the PIN check
D Input — reading the PIN from the user

Question 2: Algorithm Characteristics

Which of the following is NOT a characteristic of a well-defined algorithm?

A It must end (Finiteness)
B It must have at least one input
C It must be written in a programming language like Python
D Each step must be clear (Definiteness)

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

8

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!"

Scroll to Top