CS FundamentalsVery hardProduct company interview · GATE level
Counting every simple condition of a compound boolean expression as a separate decision (each && / || adds one), what is the cyclomatic complexity of this function?
Counting every simple condition of a compound boolean expression as a separate decision (each && / || adds one), what is the cyclomatic complexity of this function?
def total(a, n):
s = 0
i = 0
while i < n:
if a[i] < 0 and i % 2 == 0:
break
elif a[i] == 0 or a[i] > 100:
i += 1
continue
s += a[i]
i += 1
return s- A. 6
- B. 4
- C. 10
- D. 14
Correct answer: A. 6
Predicates: the while test (1), a[i] < 0 and i % 2 == 0 (2), a[i] == 0 or a[i] > 100 (2): 5 simple decisions, so V(G) = 6; break and continue add edges, not decisions. Treating each if/elif as one decision gives 4, and 10 and 14 are the node and edge counts, not E − N + 2.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- What is the cyclomatic complexity of this fragment? Count each case label other than default as one decision and each simple condition…
- A loop body contains an if-else followed by an independent if (with no else), and nothing else that branches. The loop runs between 0 and…
- A function has 4 independent integer inputs, each with a closed valid range. How many test cases do robust boundary value analysis (min…
- A form has three inputs. Input A has 3 valid and 2 invalid equivalence classes, B has 4 valid and 1 invalid, and C has 2 valid and 2…
- What is the minimum number of test cases that achieves MC/DC (unique-cause modified condition/decision coverage: for every condition, two…
- A configuration test has four parameters: browser (4 values), OS (3 values), language (2 values) and network (2 values). What is the…