Skip to main content

What is an algorithm flowchart?

Short answer

An algorithm flowchart is a graphical representation of an algorithm's logic using standardized blocks (start/end, process, decision, input/output, connectors) and directional arrows that show the sequence in which steps are executed.

Detailed breakdown

Why algorithm flowcharts are needed

  • Visualizing complex logic: helps you quickly understand the structure of branches and loops.
  • Team communication: a common language for developers, analysts, and testers.
  • Finding errors and ambiguities: makes it easier to review an algorithm before writing code.
  • Documentation and training: reinforces knowledge of the system and speeds up onboarding.

Main elements and their meaning

  • Oval (Terminator): the start/end of the algorithm.
  • Parallelogram (Input/Output): reading or displaying data (for example, "Read n", "Print the result").
  • Rectangle (Process): an operation/action (assignment, computation, a function call).
  • Diamond (Decision): checking a condition with outcomes (usually Yes/No), leading to branching.
  • A rectangle with a double side line (Subprocess): a call to a subroutine/function, hiding the details.
  • Round connector (Connector): a transition between parts of the diagram or a carry-over to the next page (labels A, B, ...).
  • Arrows (Flow): the direction of control flow; try to avoid crossings and ambiguity.

Example 1: Checking whether a number is even

Task: determine whether a number n is even, and print the result.

  • Start (oval).
  • Input n (parallelogram).
  • Compute n % 2 (rectangle).
  • Condition: is the remainder equal to 0? (diamond).
  • Yes → print "even"; No → print "odd" (parallelograms).
  • End (oval).
text
Pseudocode: START READ n r := n mod 2 IF r = 0 THEN PRINT "even" ELSE PRINT "odd" ENDIF END
javascript
function isEven(n) { return n % 2 === 0; } const n = Number(prompt('Enter a number:')); if (Number.isFinite(n)) { if (isEven(n)) { console.log('even'); } else { console.log('odd'); } } else { console.log('invalid input'); }
text
+-------+ +-----------+ +-------------+ +------------+ | START | ---> | READ n | ---> | r := n % 2 | ---> | r == 0 ? | +-------+ +-----------+ +-------------+ +------+-----+ | Yes | No | v v +-----------+ +--------------+ | PRINT | | PRINT | | "even" | | "odd" | +-----------+ +--------------+ \ / v v +-------+ | END | +-------+

Example 2: Finding the maximum in an array

Task: find the maximum element in a non-empty array nums.

  • Start; read the array.
  • Initialize max = nums[0].
  • Loop over the remaining elements: compare and update max if needed.
  • Print max; end.
text
Pseudocode: START READ nums (length > 0) max := nums[0] FOR i := 1 TO length(nums)-1 DO IF nums[i] > max THEN max := nums[i] ENDIF ENDFOR PRINT max END
javascript
function maxInArray(nums) { if (!Array.isArray(nums) || nums.length === 0) { throw new Error('The array is empty or invalid'); } let max = nums[0]; for (let i = 1; i < nums.length; i++) { if (nums[i] > max) max = nums[i]; } return max; } console.log(maxInArray([3, 7, -2, 10, 5])); // 10

Good formatting practices

  • One entry point (Start) and one exit point (End) for simple procedures.
  • Flow from top to bottom and left to right; avoid crossing arrows.
  • Short labels inside blocks; move details into subprocesses.
  • Consistency: label condition outcomes the same way (for example, "Yes" to the right, "No" downward).
  • Loops: the condition in a diamond, a backward arrow to the loop body; label the condition explicitly.
  • Replace long jumps with labeled connectors (A, B, ...).

Typical mistakes

  • No explicit end of the algorithm, or several unclosed branches.
  • Mixing data and control: input/output through a process block instead of a parallelogram.
  • Undefined conditions: a diamond without labeled outcomes, or ambiguous arrows.
  • Excessive detail at one level: overloaded diagrams are harder to read.

When to use a flowchart

  • Useful for:
    • Working out business logic, conditions, and exceptions before coding.
    • Explaining an algorithm to a non-technical audience.
    • Documenting critical areas: payments, authorization, error handling.
  • Less useful for:
    • Trivial functions, where the code is more compact and clearer.
    • Fast iterations, where the diagram becomes outdated faster than the code.

How a flowchart relates to code

  • Rectangle ↔ statements/operators (assignment, a function call).
  • Diamond ↔ if/else or while with a condition; the Yes/No outcomes correspond to the true/false branches.
  • A for/while loop is drawn as a diamond (the check) plus a backward arrow to the loop body (a rectangle).
javascript
// Example of the correspondence to a flowchart: let sum = 0; // Process for (let i = 0; i < n; i++) { // Decision (i < n?) + backward arrow sum += a[i]; // Process (loop body) } if (sum > 100) { // Decision (sum > 100?) console.log('big'); // I/O } else { console.log('small'); // I/O }

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.