1.4.0 Introduction
In the previous subchapters, you explored how algorithms are used in both everyday life and computer science. Now, it’s time to learn how to represent those algorithms in a clear, standardized way before actually coding them. Two key tools for this are:
- Flowcharts: A diagrammatic method of showing the steps in an algorithm.
- Pseudocode: A text-based way to describe how an algorithm works, using structured English rather than an actual programming language.
By the end of this lesson, you will be able to:
- Understand the basic symbols and structure used in flowcharts.
- Write pseudocode for a simple algorithm.
- Recognize how these techniques bridge the gap between your problem-solving approach (algorithm) and actual code in later lessons.
1.4.1 Why Represent Algorithms Visually and in Text?
- Clarity and Communication
- Visuals (flowcharts) help you see the flow of steps at a glance—especially useful for spotting possible loops or decision points.
- Pseudocode ensures that everyone on a team (students, teachers, or even professional developers) can discuss an algorithm without worrying about the syntax of a specific programming language.
- Planning Before Coding
- By drawing a flowchart or writing pseudocode, you can spot logical errors early.
- It’s much easier to correct a flowchart or rewrite pseudocode than it is to debug hundreds of lines of code.
- Structured Thinking
- Flowcharts highlight decision-making (e.g., “If condition is true, do X; else do Y”) and how tasks connect.
- Pseudocode enforces sequential thinking (e.g., do Step 1, then Step 2), making you practice a clear, logical approach.
1.4.2 Flowcharts: Visualizing the Steps
Flowcharts use a standard set of symbols to depict different kinds of actions or decisions. While there can be more symbols in advanced diagrams, the following are the core ones:
- Start/End (Terminator)
- Usually an oval shape with the word “Start” or “End”.
- Tells you where the algorithm begins and ends.
- Process
- A rectangle indicates a typical instruction or action. For instance, “Mix the ingredients” in a cooking algorithm, or “Set score = 0” in a game.
- Input/Output
- A parallelogram shape represents data input or output. For example, “Enter username” or “Display final score”.
- Decision
- A diamond shape indicates a yes/no (true/false) question. For example, “Is the user password correct?” branches to “Yes” or “No”.
- Arrows (Flow Lines)
- Arrows connect the shapes in the order that steps are carried out.
Example Flowchart
┌────────────┐
│ Start │
└────────────┘
↓
┌────────────────────┐
│Enter user’s number │ <– Input
└────────────────────┘
↓
┌────────────────────┐
│Check if number > 10 │ <– Decision
└────────────────────┘
┌─────┴─────┐
Yes↓ ↓No
┌────────────────────┐
│Print “Above 10” │ <– Process
└────────────────────┘
↓
┌────────────────────┐
│ End │
└────────────────────┘
This example shows a simple algorithm to input a number and decide if it’s greater than 10.
1.4.3 Pseudocode: Structured Text Descriptions
Pseudocode is a concise way of writing out the steps of an algorithm using plain language that resembles programming logic. It’s not tied to any specific language like Python or C++, but it borrows common coding structures (if-else, loops, variables).
- Common Pseudocode Keywords
- INPUT: for entering data (e.g., INPUT userNumber)
- OUTPUT: for displaying results (e.g., OUTPUT “Above 10”)
- IF, ELSE, ENDIF: for decisions
- WHILE, FOR, ENDWHILE, ENDFOR: for loops
- Structure
- Each step is on a new line, often indented for clarity (especially inside loops or if-else blocks).
- Variables are typically declared or used without strict data type definitions in basic pseudocode (e.g., SET score = 0).
Example
Using the same logic from the flowchart:
START
INPUT userNumber
IF userNumber > 10 THEN
OUTPUT “Above 10”
ELSE
OUTPUT “Not above 10”
ENDIF
END
- Why Use Pseudocode First?
- You can quickly revise it if you notice logical issues.
- It’s easier to read for beginners than jumping straight into a specific language’s syntax.
1.4.4 Flowchart vs. Pseudocode: Differences & Synergy
- Flowchart
- Visual format, good for big-picture understanding.
- Best for branching logic and seeing how decisions connect.
- Occasionally more time-consuming to create for very large algorithms.
- Pseudocode
- Textual format, mirrors real programming more closely.
- Easier to transform directly into source code once verified.
- Great for detailing smaller or more linear parts of the algorithm.
- When to Use Which
- Flowchart: Early stages, especially if the algorithm is full of branches or loops.
- Pseudocode: When preparing to code, or if you need a line-by-line breakdown.
- Often, a project will use both to clarify logic from different perspectives.
1.4.5 Applied Activity: Creating a Flowchart & Pseudocode for a Real-Life Scenario
- Choose a Scenario
- Example: “Deciding whether or not you can go out to play” (with conditions like checking homework completion, checking time or parental permission).
- Write the Flowchart
- Identify a Start and End.
- Insert Decision diamonds for conditions (e.g., “Homework done?”, “Is it before dinner time?”).
- Use Arrows to branch “Yes” and “No” paths.
- Write the Pseudocode
- Translate each step into structured text.
- Use IF and ELSE for decisions, and OUTPUT for final messages (e.g., “Go outside to play” or “You can’t go out yet”).
- Peer Evaluation
- Swap with a classmate to see if they can understand your flowchart/pseudocode.
- Check for clarity, proper sequence, and a definite end condition.
1.4.6 Conclusion & Preview of Next Chapter
By combining flowcharts and pseudocode, you can visualize and describe algorithms systematically—whether they involve deciding if a number is bigger than 10 or planning your weekend routine. These representations help bridge the gap between logical thinking and actual code.
Looking Ahead: In the next chapter, you’ll start exploring basic computer systems and how software interacts with hardware at a deeper level. Understanding this will give you valuable insights into why your flowcharts and pseudocode eventually translate into the instructions a computer can execute. You’ll also begin connecting these algorithm concepts to real programming tasks, seeing firsthand how the building blocks of computing come together in practical scenarios.