Search: "root cause analysis"
Sample Exam Questions
Back to results
CTAL-TTA LO: TTA-3.2.1 2 questions
Learning Objective: Use control flow analysis to detect if code has any control flow anomalies and to measure cyclomatic complexity
Download PDFs:
Q11
K3 TTA-3.2.1

Below is the pseudo-code for a TRICKY program:

0 program TRICKY
1 var1, var2, var3 : integer
2 begin
3     read(var2)
4     read(var1)
5     while var2 < 10 loop
6               var3 = var2 + var1
7               var2 = 4
8               var1 = var2 + 1
9               print(var3)
10             if var1 = 5 then
11                   print(var1)
12             else
13                   print(var1+1)
14             endif
15             var2 = var2 + 1
16     endloop
17     print(“Wow – that was tricky!”)
18     print(“But the answer is...”)
19     print(var2+var1)
20 end program TRICKY

Which of the following statements about the TRICKY program MOST correctly describes any
control flow anomalies in it?

Select ONE option.

  • A.

    The TRICKY program contains no control flow anomalies

  • B.

    The TRICKY program contains unreachable code and an infinite loop

  • C.

    The TRICKY program contains unreachable code and no infinite loop

  • D.

    The TRICKY program contains a loop with multiple entry points

Q12
K3 TTA-3.2.1

The programmers have designed three versions of a function that finds the largest number among three integers: findMax1, findMax2 and findMax3. One of them must be chosen for the next release. The codes look as follows:

int findMax1(int n1, int n2, int n3) {
    int max;
    if (n1 >= n2 && n1 >= n3)
         max = n1;
    if (n2 >= n1 && n2 >= n3)
        max = n2;
    if (n3 >= n1 && n3 >= n2)
        max = n3;
    return max;
}

int findMax2(int n1, int n2, int n3) {
      int max;

      if (n1 >= n2 && n1 >= n3)
           max = n1;
      else if (n2 >= n1 && n2 >= n3)
           max = n2;
      else
          max = n3;
      return max;
}

int findMax3(int n1, int n2, int n3) {
      int max;
      if (n1 >= n2) {
          if (n1 >= n3)
               max = n1;
          else
               max = n3;
      } else {
           if (n2 >= n3)
               max = n2;
           else
               max = n3;
      }
      return max;
}

You were asked to select the one with the lowest cyclomatic complexity. Which ONE should you choose?

Select ONE option.

  • A.

    findMax1

  • B.

    findMax2

  • C.

    findMax3

  • D.

    You can choose any of them, because all three functions have the same cyclomatic complexity

Share Your Feedback

How is your experience with TBoK?