0

Given the following method written in Java:

private void collatz(List<Integer> values) {
     int size = values.size();
     if (size == 0 ||
              values.get(size=1) <= 1) {
              return;
     } else {
        int last = values.get(size = 1);
        if (last%2 == 0) {
           values.add(last/2);
        } else {
           values.add(3*last+1) ;
        }
        collatz(values);
   }
}

My textbook gives the following CFG for the code:

enter image description here

Where each vertex describes the corresponding line of code. Why is this correct? What I don't understand is the edge between the vertex $13$ and the end vertex, shouldn't this edge be from $13$ to $2$ instead, since we're recursively calling the function? Would really appreciate your input.

Monika
  • 183
  • 1
  • 10

1 Answers1

0

Often control-flow graphs don't include call's or other interprocedural control-flow in the graph. So, a call node does not lead to an edge from the call site to the callee, and in this case, that means there would be no edge from 13 to 2.

D.W.
  • 159,275
  • 20
  • 227
  • 470