Brain Dump

Flow Chart

Tags
math

A special graph used to represent an algorithm.

ElementShapeExample Text
Instruction\text{\tikz \draw (0,0) rectangle (2, 1);}Print B
Decision (yes/no)\text{\tikz [rotate=45] \draw (0,0) rectangle (1,1);}if \( x < 5 \)
Start/Finish\text{\tikz \drawrounded corners rectangle (2,1);}Start

For example you can visualise Euclid's algorithm as a flow chart in fig:euclid-flow.

\begin{figure}
  \centering
  \begin{tikzpicture}
    \node (start) [draw, rectangle] {Start};
    \node (input) [draw, rectangle, below=of start] {Input \( a, b \qquad a \geq b \)}
      edge [<-] (start);
    \node (letp) [draw, rectangle, below=of input] {Let $P$ = Integer part of \( \frac{a}{b} \)}
      edge [<-] (input);
    \node (letq) [draw, rectangle, below=of letp] {Let \( q = Pb \)}
      edge [<-] (letp);
    \node (letr) [draw, rectangle, below=of letq] {Let \( r = a - q \)}
      edge [<-] (letq);
    \node (ris0) [draw, diamond, below=of letr] {Does \( r = 0 \)?}
      edge [<-] (letr);
    \node (printb) [draw, rectangle, right=of ris0] {Print $b$}
      edge [<-] node [midway,above] {Yes} (ris0);
    \node (stop) [draw, rectangle, right=of printb] {Stop}
      edge [<-] (printb);
    \node (loop) [draw, rectangle, below=of ris0] {Let \( a = b, b = r \)}
      edge [<-] node[midway, left] {No} (ris0)
      ;
    \draw [->] (loop.west) -- ++(-1, 0) |- (letp);
  \end{tikzpicture}
  \caption{Euclids algorithm visualised as a flow chart.}
  \label{fig:euclid-flow}
\end{figure}