Prev Main Next

Flowgraphs

You might have learned how to think about algorithms using flowgraphs, also called flowcharts. For example, the previous page gave the following Java program fragment to tell whether a number is composite.

  boolean isComposite;
  int i;
  for(i = 2; i < n; i++) 
  {
    if(n % i == 0) break;
  }
  if(i < n) isComposite = true;
  else isComposite = false;
A flowgraph shows the program graphically.

Flowgraphs are useful tools for grasping concepts of flow of control. A loop in the program, for example, shows up as a cycle in the flowgraph.

But you will need to avoid letting flowgraphs become more crutches than tools. When you just begin to learn a foreign language, you might translate each sentence into your own native language to understand it. But soon, you find that cumbersome, and instead you learn to understand sentences without translating them.

It is important to learn to read and hand-simulate Java programs without first writing them as flowgraphs. Drawing flowgraphs takes too much time. Also, when you cover more advanced material, you find that flowgraphs are more of a hindrance than a help. The reason is that flowgraphs concentrate on flow of control, but some other aspects of Java concentrate on flow of information, or on relationships among types of things.


Prev Main Next