Skip to main content
Learn ยท Computer Science ยท Class 8

Algorithms & Flowcharts

Designing a solution before writing any code.

10 parts
Scroll to begin โ†“
๐Ÿ“˜ DefinitionWhat makes an algorithmPart 1 of 10
๐Ÿงฉ The partsFlowchart symbolsPart 2 of 10
๐Ÿ” In detailPseudocodePart 3 of 10
โœ๏ธ Worked exampleDesigning an algorithm from scratchPart 4 of 10
๐Ÿ” In detailSearching and sortingPart 5 of 10
โœ๏ธ Worked exampleTesting an algorithm properlyPart 6 of 10
๐ŸŒ In the real worldWhere algorithmic thinking helpsPart 7 of 10
โš ๏ธ Common mistakesWhere it usually goes wrongPart 8 of 10
โœ… SummaryWhat to rememberPart 9 of 10
โœ๏ธ Worked exampleWatch one worked throughPart 10 of 10
1๐Ÿ“˜ DefinitionPart 1 / 10

What makes an algorithm

An algorithm is a finite sequence of precise steps that solves a problem.

Four requirements:

  • Precise, each step is unambiguous.
  • Finite: it terminates.
  • Effective: each step can actually be carried out.
  • General: it works for any valid input, not one example.

That last point is what separates an algorithm from a solution to one particular case.

2๐Ÿงฉ The partsPart 2 / 10

Flowchart symbols

  • Oval: start or stop.
  • Parallelogram: input or output.
  • Rectangle: a process or calculation.
  • Diamond: a decision, with exactly two exits labelled yes and no.
  • Arrows: the direction of flow.

Why diagram it first: a mistake in a flowchart takes seconds to fix. The same mistake found in code can take an hour, and may not announce itself at all.

Every flowchart has exactly one start and at least one stop.

3๐Ÿ” In detailPart 3 / 10

Pseudocode

Pseudocode writes an algorithm in structured English, precise enough to be unambiguous, but not tied to any language.

BEGIN
  INPUT n
  SET total = 0
  FOR i = 1 TO n
    total = total + i
  END FOR
  OUTPUT total
END

Its advantage over a flowchart: it handles loops and nesting far more compactly, and translates almost directly into any programming language.

Flowcharts are better for showing branching visually; pseudocode is better for anything long.

4โœ๏ธ Worked examplePart 4 / 10

Designing an algorithm from scratch

Problem. Find the largest number in a list.

The trap: you glance at a list and see the largest instantly. A computer sees one value at a time, so the algorithm must reflect that constraint.

The design:

SET largest = first item
FOR each remaining item
  IF item > largest THEN
    SET largest = item
  END IF
END FOR
OUTPUT largest

Why start with the first item rather than zero? If every number were negative, starting at zero would return zero, which is not in the list. Starting with a real value avoids that.

Now trace it by hand on [4, 9, 2, 7]. Then test the edge cases: one item, all equal, all negative. This is where algorithms break.

5๐Ÿ” In detailPart 5 / 10

Searching and sorting

Linear search: check every item until you find it. Works on any list; slow for long ones.

Binary search: only on a sorted list. Check the middle; if the target is smaller, discard the entire upper half, and repeat.

The difference in scale is dramatic: in a list of 1,000,000 items, linear search may need a million checks. Binary search needs about 20.

Each step halves the remaining possibilities, which is why it is so fast, and why the list must be sorted first.

Bubble sort repeatedly compares neighbouring pairs and swaps them if out of order. Simple to understand and inefficient for large lists.

The lesson: the choice of algorithm matters more than the speed of the computer.

6โœ๏ธ Worked examplePart 6 / 10

Testing an algorithm properly

An algorithm that works on your example may still be wrong.

Three kinds of test data:

  • Normal, typical values. A mark of 65 for a pass/fail program.
  • Boundary: exactly on the limit. 49, 50 and 51 if the pass mark is 50. Most errors live here, because of confusion between > and ≥.
  • Erroneous: invalid input. A negative mark, a mark of 150, or letters instead of numbers.

Trace tables are the tool for checking by hand: a column for each variable, a row for each pass through the loop. Fill it in manually and you will see exactly where the values go wrong.

The habit worth building: when you think an algorithm is finished, deliberately try to break it. Testing only the case you designed for proves nothing.

7๐ŸŒ In the real worldPart 7 / 10

Where algorithmic thinking helps

Beyond programming. Breaking a large problem into precise steps, decomposition, works on essays, experiments and revision plans.

Recognising patterns. Noticing that a new problem resembles one you have solved is how experienced programmers work quickly.

Everyday algorithms. Recipes, assembly instructions and directions are all algorithms, and the good ones share the same properties: precise, finite, ordered.

Understanding the systems around you. Search results, recommendations and content feeds are all algorithms making decisions. Knowing they are designed by people, with particular goals, is worth more than knowing any specific one.

8โš ๏ธ Common mistakesPart 8 / 10

Where it usually goes wrong

  • "An algorithm is code." It is the plan; code is one expression of it.
  • Writing code before designing.
  • Binary search on an unsorted list. It gives wrong answers silently.
  • Testing only normal data.
  • Decision boxes with three exits. Exactly two.
  • Loops with no way to terminate.
9โœ… SummaryPart 9 / 10

What to remember

  • Algorithms are precise, finite, effective, general.
  • Design first: flowchart for branching, pseudocode for length.
  • Binary search needs a sorted list and is dramatically faster.
  • Test normal, boundary and erroneous data.
10โœ๏ธ Worked examplePart 10 / 10

Watch one worked through

Here is one done slowly, with the reason for every move. Then one for you.

Watch one first

Draw the logic of a flowchart that reads a number and prints whether it is even or odd.

  1. Start, then input the number.
    (Start) โ†’ [ INPUT n ]
    Every flowchart has exactly one start. An oval is for start and stop, a parallelogram for input and output.
  2. Add the decision as a diamond with a yes and a no branch.
    < n รท 2 has remainder 0 ? >
    A decision box must have exactly two exits. If a question cannot be answered yes or no, it is not a decision box.
  3. Send each branch to its own output.
    YES โ†’ [ PRINT "Even" ] NO โ†’ [ PRINT "Odd" ]
    Both branches must lead somewhere. A path that just stops is the commonest mistake in a drawn flowchart.
  4. Rejoin the branches and stop.
    both โ†’ (Stop)
    Bringing the paths back together keeps one exit, which matters as soon as the chart grows.

Answer: Start, input n, decision on whether the remainder after dividing by 2 is zero, print Even on yes and Odd on no, then stop

Now you try

Which flowchart shape is used for a decision? One word.

Show the answer

diamond

Practise Algorithms & Flowcharts

Everything on QuizByt for Class 8 Computer Science that goes with this lesson: read it first, then test yourself while it is fresh.

๐Ÿง  17 quizzes on Algorithms & Flowcharts (14 easy, 2 medium, 1 hard)

Work up from easy to hard: the hard quiz asks the Class 8 exam-style questions on Algorithms & Flowcharts.

๐Ÿ–จ๏ธ Printable worksheet

Algorithms & Flowcharts on paper for Class 8, with room to write the working out. Preview the first page free.

๐ŸŽฎ Games for Class 8 Computer Science

Memory and reasoning games at the right level for Class 8. Passing a quiz on Algorithms & Flowcharts earns the credits that open them.

Now test yourself

You have read the whole lesson. Take the quiz on this topic to see how much stuck,a free account is all it takes.

  • ๐Ÿ“Š Your score is saved, so you can see progress over time
  • ๐Ÿ” See exactly which questions you got wrong, and why
  • ๐Ÿ’Ž Earn credits for every quiz you pass, and spend them on games

In a hurry? Try a free Computer Science quiz with no account.