VM-LEARNING /class.xi ·track.cs ·ch-2-1 session: 2026_27
$cd ..

~/Introduction to Problem Solving

root@vm-learning ~ $ open ch-2-1
UNIT 2 ▪ CHAPTER 1
07
Introduction to Problem Solving
Steps · Algorithms · Flowcharts · Pseudocode · Decomposition
Problem solving is the process of identifying a problem, understanding it in detail, and producing a step-by-step method that leads to a correct solution. In computer science, the goal is usually to translate a real-world problem into a program — a precise sequence of instructions a computer can execute. Before writing even a single line of Python code, you first analyse, design, and plan. This chapter teaches you how — the five-step workflow, two ways of expressing an algorithm (flowcharts and pseudocode), and the powerful idea of decomposition.
Why this matters. Real programmers do not start by typing code. They:
  • Read the problem carefully and list inputs, outputs and constraints.
  • Design an algorithm on paper (or in their head).
  • Only then translate the algorithm to code.
  • Test it on sample inputs and fix mistakes (debugging).
This pattern saves hours of wasted typing. It is also what the CBSE examiner expects you to show — a correct flowchart or pseudocode can earn most of the marks even if the final program has small errors.
Learning Outcome 1: Describe the five steps of problem solving and apply them to a simple problem.

4.1 The Five Steps of Problem Solving

Every programming task — from a 3-line print statement to a banking application — follows the same five steps:

The problem-solving workflow: 1. Analyse understand the problem 2. Design develop an algorithm 3. Code translate to Python syntax 4. Test run on sample inputs 5. Debug find & fix errors if a bug is found, go back and redesign The five steps of every programming task

4.1.1 Step 1 — Analysing the Problem

Read the problem statement several times. Ask yourself three essential questions:

Example — find the area of a rectangle.
  • Input: length L and breadth B (both positive numbers).
  • Output: area A.
  • Processing: A = L × B.
Once these three are clear, the design step practically writes itself.

4.1.2 Step 2 — Developing an Algorithm

Write the sequence of steps that transform the input into the output. Keep the steps language-independent — plain English is fine. You will express this algorithm either as a flowchart or as pseudocode (covered in §4.3 and §4.4).

4.1.3 Step 3 — Coding

Translate each step of the algorithm into real Python (or any chosen language). Use clear variable names, follow indentation rules, and add comments that explain why a piece of code exists, not what it does (well-named variables already say that).

4.1.4 Step 4 — Testing

Run the code on carefully chosen sample inputs — not only the "happy path", but also edge cases: zero, negative numbers, very large numbers, empty strings, wrong types. Verify the output against what you computed by hand.

4.1.5 Step 5 — Debugging

If an output is wrong (or the program crashes), debugging is the detective work of finding and fixing the cause. Common techniques:

Once the fix is applied, go back to Test with more inputs. The cycle Code → Test → Debug repeats until the program is correct.

Learning Outcome 2: Define an algorithm and list its key characteristics.

4.2 What is an Algorithm?

An algorithm is a finite, ordered sequence of clear instructions that solves a specific problem. It must be precise enough that anyone (or any machine) following the steps blindly will produce the correct output.
The word algorithm is named after the 9th-century Persian mathematician Al-Khwarizmi, whose book on arithmetic gave Europe the decimal number system.

4.2.1 Characteristics of a Good Algorithm

PropertyMeaning
InputTakes zero or more well-defined inputs.
OutputProduces at least one output.
DefinitenessEvery step is precise and unambiguous — no "maybe", "sometime", etc.
FinitenessMust end after a finite number of steps.
EffectivenessEach step is simple enough to be carried out in a reasonable time.
GeneralityWorks for an entire class of inputs, not a single specific case.
Algorithm — find the area of a rectangle:
Step 1: Start
Step 2: Read length L and breadth B
Step 3: Compute Area = L × B
Step 4: Print Area
Step 5: Stop
Five short, unambiguous, finite steps — a valid algorithm.
Learning Outcome 3: Represent an algorithm using a flowchart and using pseudocode.

4.3 Representing an Algorithm — Flowcharts

A flowchart is a pictorial representation of an algorithm using a small set of standard shapes connected by arrows. It is the easiest way to visualise how control moves through a program — especially when conditions and loops are involved.

4.3.1 Standard Flowchart Symbols

The six essential flowchart symbols: Start / Stop Terminal begins / ends a flow Input / Output Data read / print a value Process Process calculation or assignment Decision? Decision yes / no branch A Connector joins two parts of a chart Flow line direction of control Example — "Find area of a rectangle" Start Read L, B A = L × B Print A Stop

4.3.2 Flowchart — With a Decision

Decisions are where flowcharts really shine. The diamond has one entry and two exits (yes / no).

Flowchart — "Is a number positive, negative or zero?" Start Read N N > 0 ? Print "Positive" N = 0 ? Print "Zero" Print "Negative" Yes No Yes No

4.4 Representing an Algorithm — Pseudocode

Pseudocode is a way of describing an algorithm using structured English that looks like code but is not bound by any real language's syntax. It is quicker to write than a flowchart and easier to convert into Python.

4.4.1 Pseudocode Conventions

Pseudocode — Area of a rectangle:
BEGIN
    INPUT L, B
    SET A ← L × B
    OUTPUT A
END
Pseudocode — Positive / Negative / Zero:
BEGIN
    INPUT N
    IF N > 0 THEN
        OUTPUT "Positive"
    ELSE IF N = 0 THEN
        OUTPUT "Zero"
    ELSE
        OUTPUT "Negative"
    ENDIF
END
Compare with the flowchart above — the two are equivalent representations of the same algorithm.

4.4.2 Flowchart vs. Pseudocode — When to use Which

CriterionFlowchartPseudocode
VisualYes — picturesNo — text only
Easier for beginners
Closer to actual code
Handles big programsBecomes messyScales well
Drawing tools neededYes (or pen & paper)Just a text editor
Learning Outcome 4: Explain decomposition and apply it to break a complex problem into smaller parts.

4.5 Decomposition

Decomposition is the process of breaking a large, complicated problem into smaller, manageable sub-problems that are easier to solve individually. Each sub-problem becomes a function or a module in the final program. This is the central strategy of computational thinking.

Think of decomposition as how you'd answer the question "How do you cook a full thali?" — you don't answer in one breath; you break it down: cook rice, cook dal, cook sabzi, make chapatis, make salad. Each of those is itself a mini-problem with its own steps. The same idea applies to programs.

4.5.1 Example — Build a Student Report-Card Program

"Write a program to generate report cards for a class of students" sounds intimidating. But after decomposition:

Decomposition tree: Generate Report Cards (main problem) 1. Read student data • name • roll number • marks of 5 subjects → input() / file read 2. Compute totals • total = sum of 5 subjects • percentage = total ÷ 500 × 100 • round to 2 decimals → arithmetic function 3. Assign grade • ≥ 75 → A • 50 – 74 → B • < 50 → C → if / elif / else 4. Print report card • header with logo • name / roll / marks • total, %, grade → formatted print() Each sub-problem becomes its own Python function. The main program just calls them in order.

4.5.2 Benefits of Decomposition

Golden rule: A sub-problem is "small enough" when you can write its algorithm in 5–10 lines without further decomposition. If it's still too complex, break it down again.

📌 Quick Revision — Chapter 4 at a Glance

  • Problem solving = turning a real-world problem into a step-by-step solution a computer can execute.
  • Five steps: (1) Analyse — list input, output, processing; (2) Design algorithm; (3) Code in Python; (4) Test on sample inputs; (5) Debug until correct. The cycle 3-4-5 repeats.
  • Algorithm = finite, ordered, precise sequence of steps that solves a class of problems. Named after Al-Khwarizmi.
  • Six characteristics of a good algorithm: Input, Output, Definiteness, Finiteness, Effectiveness, Generality.
  • Flowchart = pictorial algorithm using 6 shapes: Oval (start/stop), Parallelogram (I/O), Rectangle (process), Diamond (decision), Circle (connector), Arrow (flow).
  • Pseudocode = algorithm written in structured English (BEGIN … END, INPUT, OUTPUT, IF-THEN-ELSE, WHILE, FOR). No specific language's syntax.
  • Flowchart is better for visualising small problems; pseudocode scales to bigger ones and is closer to real code.
  • Decomposition = break a big problem into small, independent sub-problems. Each sub-problem becomes a function.
  • A sub-problem is small enough when its algorithm fits in 5–10 lines without further breakdown.
  • Decomposition makes programs easier to think about, test, reuse, share and debug.
🧠Practice Quiz — test yourself on this chapter