🧩 Problem Solving

Algorithms & Flowcharts

एल्गोरिदम और फ्लोचार्ट

⏱ 3 hr3 topicsInteractive
🎯 By the end: You can write a step-by-step algorithm, draw a flowchart with the correct symbols, write pseudocode, and tell apart syntax, logical and runtime errors.

Good programmers don't start by typing code — they start by thinking. Before a single line of Python, you work out the steps to solve the problem. This chapter is about that planning stage: algorithms, flowcharts and pseudocode. Master it and your actual coding becomes far easier and far less buggy.

1Algorithms and pseudocode

An algorithm is a finite, step-by-step set of instructions to solve a problem. A good algorithm is precise (no ambiguity), finite (it ends), and produces the correct result. You write algorithms in plain language. For example, to find the larger of two numbers A and B:

Step 1: Start
Step 2: Read A and B
Step 3: If A is greater than B, then the larger is A
Step 4: Otherwise the larger is B
Step 5: Display the larger value
Step 6: Stop

Pseudocode is a halfway point between plain English and real code — structured like a program but not tied to any language's exact syntax. It lets you focus on logic:

INPUT A, B
IF A > B THEN
    PRINT A
ELSE
    PRINT B
ENDIF
Key points
  • An algorithm is a precise, finite, step-by-step method to solve a problem.
  • It must be unambiguous, end after a finite number of steps, and give the correct result.
  • Pseudocode is structured, language-independent code that captures the logic before you write real syntax.

2Flowcharts and their symbols

A flowchart is a picture of an algorithm, drawn with standard symbols joined by arrows showing the flow of control. Each symbol has a specific meaning:

Symbol shapeMeaning
Oval / roundedTerminal — Start or Stop
ParallelogramInput / Output — read data or display result
RectangleProcess — a calculation or action
DiamondDecision — a yes/no question (branches)
ArrowsFlow lines — the order of steps
StartRead A, BA > B ?Print APrint BStopYesNo
Key points
  • A flowchart pictures an algorithm using standard symbols joined by flow-line arrows.
  • Oval = Start/Stop (terminal); parallelogram = input/output; rectangle = process; diamond = decision.
  • A decision (diamond) has a yes/no question and branches the flow.

3Errors: syntax, logical and runtime

When you write code, three kinds of error can appear. Telling them apart is a frequent exam question and a real debugging skill:

Error typeWhat it isExample
Syntax errorBreaking the language's grammar rules — the code won't run at allMissing colon: if x > 5 (no :)
Runtime errorCode is grammatically valid but crashes while runningDividing by zero, using a name that doesn't exist
Logical errorCode runs without crashing but gives the wrong answer — the logic is flawedUsing + where you meant *
Logical errors are the sneakiest — the program runs happily and produces output, but the output is wrong. The computer did exactly what you told it; you just told it the wrong thing. Only careful testing catches these.

Debugging is the process of finding and fixing errors, and testing means running the program with different inputs (including edge cases) to make sure it behaves correctly.

Key points
  • Syntax error: breaks grammar rules, code won't run (e.g. a missing colon).
  • Runtime error: valid code that crashes while running (e.g. divide by zero).
  • Logical error: runs fine but gives the wrong answer — only testing catches it.
  • Debugging = finding and fixing errors; testing = running with varied inputs.

★ Practical: plan before you code

On paper:

  1. Write a step-by-step algorithm to find the average of three numbers.
  2. Draw a flowchart for it using the correct symbols (terminal, input/output, process).
  3. Write the same logic as pseudocode.
  4. Classify each: a missing colon, a divide-by-zero crash, and adding instead of multiplying.

Ready for the chapter test?

Answer 5 questions. Score 60% or more to mark this chapter complete.

Start the test →

💡 Log in to save your progress and earn the certificate.