Back to Study Material School Learning

Algorithm and Flowchart

An algorithm is a finite, ordered set of unambiguous instructions that solves a specific problem or accomplishes a defined task. The word comes from the na...

Algorithm and Flowchart

What Is an Algorithm? Characteristics and Why They Matter

An algorithm is a finite, ordered set of unambiguous instructions that solves a specific problem or accomplishes a defined task. The word comes from the name of the ninth-century Persian mathematician Muhammad ibn Musa al-Khwarizmi, whose works introduced systematic mathematical procedures to Europe. Today, algorithms are the foundation of all computing — every program you use, from a search engine to a music streaming app, is built from algorithms.

For an algorithm to be valid, it must satisfy five essential characteristics. First, it must be finite — it must end after a limited number of steps. An algorithm that runs forever is a logic error. Second, it must be definite — every step must be clearly and unambiguously defined with no room for interpretation. Third, it must have input — zero or more values provided to the algorithm before it starts. Fourth, it must produce output — at least one result or effect after it finishes. Fifth, it must be effective — every step must be simple enough to be carried out exactly, in principle, with paper and pencil.

Consider a simple everyday algorithm: making a cup of tea. Step 1: boil water. Step 2: put a teabag in a cup. Step 3: pour boiling water into the cup. Step 4: wait 3 minutes. Step 5: remove teabag. Step 6: add milk and sugar as desired. Step 7: serve. This sequence is finite (7 steps), definite (each step is clear), has input (water, teabag, milk, sugar), produces output (a cup of tea), and each step is executable.

In computing, writing the algorithm before writing the actual program code is excellent practice. It forces you to think through the logic clearly, identify edge cases (what if the input is zero? what if the list is empty?), and organise your solution before worrying about syntax.

Exam tip: CBSE questions often ask students to write an algorithm for a simple task such as finding the largest of three numbers, computing the factorial of a number, or checking if a number is prime. Always number your steps and write each step on its own line.

Flowcharts: Drawing the Visual Map of Your Algorithm

A flowchart is a graphical representation of an algorithm using standardised shapes connected by arrows to show the order and flow of steps. Flowcharts make algorithms easier to understand, review, and communicate because visual representations are faster to grasp than lists of text instructions, especially when decision points and loops are involved.

Each shape in a flowchart has a specific meaning. The oval (or rounded rectangle) represents Start and End — every flowchart has exactly one start and at least one end. The rectangle represents a Process step — a calculation, assignment, or action like "Set sum = 0" or "Add 5 to total." The parallelogram (slanted rectangle) represents Input or Output — reading a value from the user or displaying a result. The diamond (rhombus) represents a Decision — a yes/no question that causes the flow to branch in two directions, such as "Is number > 0?" Arrows connect all shapes and show the direction of execution flow.

Example: flowchart for checking if a number is even or odd. Start → Input: number → Decision: Is number % 2 == 0? → Yes path: Output "Even" → End. No path from decision: Output "Odd" → End.

Loops appear in flowcharts when an arrow from a later step points back to an earlier one. For example, an algorithm that sums numbers from 1 to 10 uses a counter variable that increases by 1 each iteration, with a decision diamond checking "Is counter > 10?" — when No, the loop continues back to the addition step; when Yes, the flow exits to display the sum.

Drawing rules: arrows should never cross without a bridge symbol. Each diamond must have exactly two exit arrows labelled Yes and No (or True and False). Process boxes should contain one clear statement each. Neatness matters for exam marks.

Exam tip: CBSE board exams regularly ask students to draw a flowchart for a given algorithm, or conversely to interpret a given flowchart and describe what it computes. Practise both directions until the standard symbols and their meanings are completely automatic.

Common Algorithms: Sorting and Searching Explained Simply

Two fundamental categories of algorithms appear everywhere in computer science: sorting algorithms (arranging data in order) and searching algorithms (finding a specific item in a collection). Understanding simple versions of these at the Class 9–10 level builds a strong foundation for more advanced study.

Bubble Sort is the simplest sorting algorithm and the one most frequently taught at the school level. It works by repeatedly stepping through a list, comparing adjacent elements, and swapping them if they are in the wrong order. The largest unsorted element "bubbles up" to its correct position at the end of the list with each pass. Example: to sort [5, 3, 8, 1] using Bubble Sort: Pass 1: compare 5 and 3, swap → [3, 5, 8, 1]; compare 5 and 8, no swap; compare 8 and 1, swap → [3, 5, 1, 8]. The 8 is now in its final position. Pass 2: compare 3 and 5, no swap; compare 5 and 1, swap → [3, 1, 5, 8]. The 8 stays. Pass 3: compare 3 and 1, swap → [1, 3, 5, 8]. Sorted.

Bubble Sort requires at most n-1 passes for a list of n elements. It is simple to understand but inefficient for large lists — a list of one million items would require enormous numbers of comparisons.

Linear Search (Sequential Search) looks through every element of a list one by one until it finds the target or reaches the end. If you search for 7 in [3, 9, 7, 2, 5], you check 3 (no), 9 (no), 7 (yes — found at index 2). In the worst case, you check every element. For a list of 1000 items, you might make up to 1000 comparisons.

Binary Search is much faster but requires the list to be sorted first. It checks the middle element, and if the target is smaller, searches the left half; if larger, searches the right half. It eliminates half the remaining search space with each comparison. For 1000 sorted items, Binary Search needs at most 10 comparisons (because 2^10 = 1024).

Exam tip: for CBSE, be prepared to trace through Bubble Sort manually on a given list, showing each swap. Show every pass and clearly mark which elements have been placed in their final sorted position.