A2Z Lesson

Log in
← Back to the A2Z sheet

Step 01 Beginner Problems — Fundamentals of Programming

Flowcharts and Pseudocode

Theory

Before code, there is the plan. A flowchart is a picture of your algorithm — boxes for actions, diamonds for decisions, arrows for flow — and pseudocode is the same plan written as loose, language-free text. Planning in this form forces you to solve the logic while it is still cheap to change, and it is exactly how strong programmers sketch solutions in interviews before writing a single line.

The five flowchart symbols

You only need five shapes:

Oval (terminal) — Start and End of the algorithm. Parallelogram (input/output) — read a value, or display a value. Rectangle (process) — a calculation or assignment, e.g. sum = sum + n. Diamond (decision) — a yes/no question; two arrows leave it, one labelled Yes, one No. Arrow (flow line) — the order in which steps execute.

A loop appears naturally: draw the body in rectangles, then a diamond that asks 'are we done?' with the No arrow looping back up. If you can draw it, you can code it — every flowchart maps one-to-one onto if/else and loop statements.

Pseudocode: the same plan in words

Pseudocode keeps the structure but drops the drawing. It uses plain English mixed with programming-shaped lines — INPUT, SET, WHILE, IF...ELSE, PRINT — and indentation instead of arrows. There is no compiler and no strict syntax, so the only thing you can get wrong is the logic itself, which is precisely the point.

Write it at the level where each line will become roughly one line of real code. Too vague ('now process the array') hides the hard part; too detailed (worrying about semicolons) wastes the exercise.

Worked example: is a number a palindrome?

Plan it once, use it in every language:

INPUT n SET original = n, rev = 0 WHILE n > 0: digit = n mod 10 rev = rev * 10 + digit n = n div 10 IF rev == original: PRINT 'Palindrome' ELSE: PRINT 'Not a palindrome'

Trace it with n = 121: digits come off as 1, 2, 1 and rev builds 1 → 12 → 121, equal to the original. Notice the plan already forced the two decisions beginners forget: saving the original before destroying n, and using integer division so the loop terminates.

INPUT n SET original = n, rev = 0 WHILE n > 0: digit = n mod 10 rev = rev * 10 + digit n = n div 10 IF rev == original: PRINT "Palindrome" ELSE: PRINT "Not a palindrome"

Rules and common mistakes

One Start, one End, and every path through the chart must reach End. Label both arrows leaving a diamond — an unlabelled branch is an unmade decision. Every loop needs an exit condition that the loop body actually moves towards; if the diamond's answer can never change, you have drawn an infinite loop.

The most common beginner mistake is skipping the plan once problems feel 'easy' — then drowning in code when a medium problem arrives. Two minutes of pseudocode routinely saves twenty minutes of debugging.

Key points

  • Five symbols suffice: oval (start/end), parallelogram (input/output), rectangle (process), diamond (decision), arrows (flow).
  • A loop is just a decision diamond whose No-branch arrows back to the body — and it must have an exit the body moves towards.
  • Pseudocode is the same plan in indented words: no syntax to fight, so only logic can be wrong.
  • Each pseudocode line should become roughly one line of code — vague lines hide the hard part.
  • Plan first on anything non-trivial: two minutes of pseudocode saves twenty of debugging.

Suggested questions

Flowchart Problem-Solving Put the method to work on reverse-a-number, GCD and counting problems, start to finish.
Count all Digits of a Number ↗ The digit loop from the worked example, as a real coding problem.
Reverse a number ↗ Exactly the rev = rev * 10 + digit plan — translate your pseudocode into code.
Pattern 1 — Rectangular Star Pattern Flowcharts for loops: the nested-loop pattern starts here.

Source note: this lesson follows the structure of Striver's public A2Z DSA course (takeUforward). Each problem links to its original platform, and all problems and content belong to their respective owners — STUDY-BUDDY does not claim ownership of the sheet or its problems, and no permission beyond public linking is claimed.