Writing Algorithms - Flow Diagrams

Writing Algorithms - Flow Diagrams

Introduction to Flow Diagrams

  • A flow diagram (or flowchart) is another way to express algorithms, providing a visual representation of the logic within a program.
  • They use a set of specific symbols connected by arrows to denote flow of execution.
  • Flow diagrams can make understanding complex algorithms easier by showing each step precisely, including decisions (if statements), loops, and process steps.
  • They serve the same purpose as pseudocode, but are better at showcasing the flow of an algorithm.

Symbols Used in Flow Diagrams

  • Ovals represent the start and the end of the process.
  • Rectangles indicate a process or action to be carried out.
  • Diamond-shaped symbols represent decision points, involving a yes/no question or true/false test.
  • Arrows indicate the flow of control, showing the direction of the process.
  • Parallelograms often represent Input or Output operations.

Designing Flow Diagrams

  • Begin by identifying the start and end points of the process. These will be your oval symbols.
  • For each step in your process, use a rectangle. This could be a single operation (like ‘Increment counter’) or multiple (like ‘Calculate sum and average’).
  • Use diamonds to illustrate decisions within the algorithm, such as an if or else decision. Write the decision or condition to be tested inside the diamond.
  • Connect the symbols with arrows to show the flow of the algorithm. This should accurately represent all possible paths from start to finish.
  • Make sure your flow diagram follows a logical order and doesn’t have any breaks in the sequence.

Decomposing Problems in Flow Diagrams

  • As with pseudocode, use decomposition to break down complex problems into manageable sections.
  • Each sub-program can be represented as its own flowchart.
  • Large flowcharts can be broken down into smaller sub-processes, with a simple rectangle linking to another flowchart.

Evaluating Flow Diagrams

  • Always check the logic and the flow - does the flowchart accurately represent the problem and solve it correctly?
  • Could the flowchart be optimised or made more efficient? Look for repeated patterns or ways to simplify the logic.
  • As long as the flowchart can be understood by another person, you’ve achieved your goal! Remember, flow diagrams are about helping us think through our algorithms in a visual way.