Free Study Material

Problem Solving & Algorithms

Introduction

Before any program runs, it goes through the same four-stage journey — no matter how simple or complex the problem is. This topic names each stage and shows what happens in it.

Concept

Every program is built by working through four stages, in order:

  • Analysing the Problem — work out exactly what the inputs are, what the output should be, and what steps connect one to the other, before writing anything down.
  • Developing the Algorithm — write the solution as a precise, step-by-step sequence in plain language (see the next topic for the two standard ways to do this).
  • Coding — translate that algorithm into an actual programming language, like Python.
  • Testing & Debugging — run the code with different input values to find errors (testing), then locate and fix the exact cause of each one (debugging).

Worked Example

Take the problem: find the area of a rectangle.

1. Analysing the Problem — the inputs are the rectangle's length and breadth; the output is their product, the area.

2. Developing the Algorithm

START
INPUT length, breadth
area = length * breadth
PRINT area
STOP

3. Coding — the algorithm above translates directly into a runnable Python program:

length = float(input("Enter the length: "))
breadth = float(input("Enter the breadth: "))

area = length * breadth
print("Area of the rectangle is:", area)

4. Testing & Debugging — run this program with a few different values. Enter 5 and 4 and confirm the output reads Area of the rectangle is: 20.0. Enter 0 for the length and confirm the output reads Area of the rectangle is: 0.0, not an error. length and breadth are read with float(), so the result always prints with a decimal point, even for whole numbers. If a test value ever produces the wrong answer, the bug is fixed here, before the program is considered finished.

Note: Testing and debugging are two different actions. Testing is running the program with sample data to find out whether something is wrong. Debugging is locating and fixing the exact line causing a problem testing already found.

Explanation

The four stages are usually drawn as a one-way list, but they don't always run in a single straight line. If Testing uncovers a value the algorithm never accounts for, the fix often belongs in stage 2 — the algorithm itself was incomplete — not just in the code. That's why this is called a cycle: an error found late can send you back to an earlier stage, not just to the line of code that failed.

Summary

Every program passes through four stages in order — Analysing the Problem, Developing the Algorithm, Coding, and Testing & Debugging — and an error found during testing can send you back to an earlier stage, which is why this is a cycle rather than a strict one-way sequence.

Software Development Life Cycle (SDLC)

To create a successful program, developers don't just start typing. They follow a specific set of steps to ensure the software works correctly and solves the user's needs. This cycle is repetitive; as we find errors, we go back to previous steps to refine our solution.

1. Analyzing the Problem:

Understand the requirements. What are the inputs? What is the expected output? Are there any specific constraints?

2. Developing an Algorithm:

Create a logical plan. Use Flowcharts or Pseudocode to map out the steps before touching the keyboard.

3. Coding:

The actual translation of your algorithm into Python code. If your algorithm is good, this step is easy!

4. Testing:

Run the program with various inputs (normal, extreme, and invalid) to see if it behaves as expected.

5. Debugging:

The process of identifying the cause of an error and fixing it. Remember: "Bugs are just undocumented features!"

Decomposition

Large problems are scary. Decomposition is breaking that scary problem into smaller, tiny tasks that are easy to solve.

Example: Creating a Game
1. Handle Player Movement
2. Handle Score System
3. Handle Graphics/Sounds

Introduction

You've already seen the Problem-Solving Cycle's second stage — Developing the Algorithm — written as plain numbered steps. There are two standard, more formal ways to write that same algorithm down: a flowchart and pseudocode.

Concept

Flowchart

A flowchart is a diagram that shows an algorithm's logic using a fixed set of standard symbols, connected by arrows that show the order steps happen in.

SymbolShapeMeaning
TerminatorOvalMarks the Start or End of the algorithm
Input/OutputParallelogramTakes in a value, or displays a result
ProcessRectangleA calculation or an action on data
DecisionDiamondA yes/no or true/false question with exactly two exits
Flow LineArrowShows which step happens next

Pseudocode

Pseudocode is an algorithm written as structured, English-like statements — close enough to real code to translate directly, but not tied to any one programming language's exact syntax. It commonly uses keywords like START, STOP, INPUT, PRINT, IF, THEN, ELSE, and WHILE.

Worked Example

Take the problem: find the largest of two numbers.

As pseudocode:

START
INPUT a, b
IF a > b THEN
    PRINT a, "is the largest"
ELSE
    PRINT b, "is the largest"
END IF
STOP

As a flowchart, the same logic uses five symbols in this order: a Terminator ("Start"), an Input/Output parallelogram ("Input a, b"), a Decision diamond ("Is a > b?") with two arrows leaving it — one labelled "Yes" leading to an Input/Output parallelogram that prints a, one labelled "No" leading to an Input/Output parallelogram that prints b — and both of those arrows leading into a final Terminator ("Stop").

Coded in Python, that same pseudocode becomes:

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

if a > b:
    print(a, "is the largest")
else:
    print(b, "is the largest")

Line by line, the pseudocode maps directly onto the code: INPUT a, b became two input() calls, IF a > b THEN ... ELSE became Python's if ... else, and each PRINT became print(). This is exactly the "Coding" stage from the Problem-Solving Cycle, starting from the algorithm instead of from a blank screen.

Note: A Decision diamond always has exactly two exits — one path is followed when the condition is true, the other when it's false. It never has just one exit, and it never has three.

Explanation

Pseudocode and a flowchart are two notations for the same algorithm, not two different algorithms — CBSE questions often ask you to convert between an English problem statement, its pseudocode, and its flowchart, so recognising that all three describe identical logic matters more than memorising any one form. Pseudocode is usually faster to write and easier to revise; a flowchart makes the overall shape of the logic — especially branching — easier to see at a glance.

Summary

An algorithm can be represented as a flowchart (a diagram built from Terminator, Input/Output, Process, and Decision symbols, connected by flow lines) or as pseudocode (structured, English-like steps) — both describe the same logic, and both are written before the Coding stage.

Visualizing the Solution

Before we write code, we need a way to represent our logic that humans can understand. We use two main tools: Flowcharts (the visual map) and Pseudocode (the logical narrative).

Shape Name Function
Oval Start / Stop Used at the beginning and end.
Parallelogram Input / Output Used for getting data or showing results.
Rectangle Process Calculations (e.g., Sum = A + B).
Diamond Decision Yes/No or True/False questions.
Pseudocode Method

1. START
2. INPUT marks
3. IF marks >= 33 THEN
    PRINT "Pass"
   ELSE
    PRINT "Fail"
4. STOP

The Difference

Flowcharts are graphical. They are great for seeing the "flow" of data.

Pseudocode is text-based. It uses simple English to mimic real code without the strict rules of a programming language.

Want the full course?

Unlock all chapters, video lectures, and SQL practice exercises.

Get Full Access