Algorithms & Flowcharts
Subject: Software Applications & Programming
Program: NCO (Cyber Olympiad)
Level: Beginner / Introduction
1. Simple Explanation
| Term | What it means | Example |
|---|---|---|
| Algorithm | A step‑by‑step procedure that solves a problem or performs a task. | “Find the largest number in a list.” |
| Flowchart | A visual diagram that shows the sequence of steps (using shapes) and the flow of control between them. | A diagram that shows how to decide whether a number is even or odd. |
- Purpose of an algorithm – to give a clear, unambiguous method that a human or a computer can follow.
- Purpose of a flowchart – to make that method easy to understand at a glance and to help programmers translate it into code.
2. Key Points
| # | Concept | Why it matters |
|---|---|---|
| 1 | Input, Process, Output (IPO) | Every algorithm must take some data in, do something, and produce a result. |
| 2 | Control Structures | • Sequential – one step after another • Decision – if‑then‑else, switch • Repetition – loops (for, while, do‑while) |
| 3 | Flowchart Symbols | • Oval – start / end • Parallelogram – input / output • Rectangle – process (statement) • Diamond – decision (yes/no) • Arrow – flow of control |
| 4 | Pseudocode | Human‑readable description of an algorithm that bridges natural language and code. |
| 5 | Algorithm Efficiency | Time complexity (how running time grows with input size) and space complexity (memory usage). |
| 6 | Testing & Debugging | Verify each step with sample data; use flowcharts to spot missing branches or infinite loops. |
| 7 | Modularity | Break complex tasks into smaller sub‑algorithms; use functions/procedures. |
3. Worked Example
Problem: Compute the sum of all even numbers from 1 to n (inclusive).
Let n = 10.
3.1 Pseudocode
START
INPUT n
sum ← 0
i ← 1
WHILE i ≤ n DO
IF i MOD 2 = 0 THEN
sum ← sum + i
END IF
i ← i + 1
END WHILE
OUTPUT sum
END
3.2 Flowchart
┌───────────────┐
│ START │
└──────┬────────┘
│
┌──────▼───────┐
│ INPUT n │
└──────┬───────┘
│
┌──────▼───────┐
│ sum ← 0 │
└──────┬───────┘
│
┌──────▼───────┐
│ i ← 1 │
└──────┬───────┘
│
┌──────▼───────┐
│ i ≤ n ? │◄─────┐
└─────┬───────┘ │
│No │
┌─────▼───────┐ │
│ OUTPUT sum │ │
└─────┬───────┘ │
│ │
┌─────▼───────┐ │
│ END │◄─────┘
└─────────────┘
(The diamond represents the decision “i ≤ n ?”. If yes, go to the next step; if no, finish.)
3.3 Execution Trace (n = 10)
| i | Condition i ≤ 10? | Even? | sum after step |
|---|---|---|---|
| 1 | Yes | No | 0 |
| 2 | Yes | Yes | 2 |
| 3 | Yes | No | 2 |
| 4 | Yes | Yes | 6 |
| 5 | Yes | No | 6 |
| 6 | Yes | Yes | 12 |
| 7 | Yes | No | 12 |
| 8 | Yes | Yes | 20 |
| 9 | Yes | No | 20 |
| 10 | Yes | Yes | 30 |
| 11 | No | – | END |
Result: sum = 30
4. Quick Revision Summary
| Topic | Take‑away |
|---|---|
| Algorithm | Ordered, finite set of instructions. |
| Flowchart | Visual representation using standard symbols. |
| IPO | Every algorithm needs Input → Process → Output. |
| Control Structures | Sequence, decision, repetition. |
| Symbols | Oval (Start/End), Parallelogram (I/O), Rectangle (Process), Diamond (Decision). |
| Pseudocode | Bridge between natural language and code. |
| Efficiency | Aim for lower time/space complexity; analyze Big‑O. |
| Testing | Use sample data; trace flowchart to catch errors. |
Quick Self‑Test
- Draw a flowchart for “Find the maximum of two numbers.”
- Write pseudocode for “Reverse a string.”
- Explain why loops can lead to infinite execution if the condition never becomes false.
Good luck with your study! If you need deeper dives into specific algorithms (sorting, searching) or practice problems, just let me know.