CS FundamentalsVery hardProduct-company placement · Python
Counting each if, while and conditional expression as one decision (V(G) = decisions + 1), what is the cyclomatic complexity of g, and what do g(49) and g(1) return?
Counting each if, while and conditional expression as one decision (V(G) = decisions + 1), what is the cyclomatic complexity of g, and what do g(49) and g(1) return?
def g(n):
i, found = 2, False
while i * i <= n:
if n % i == 0:
found = True
break
i += 1
else:
return 'prime' if n > 1 else 'neither'
return 'composite' if found else 'odd'- A. 5; 'composite' and 'neither'
- B. 6; 'composite' and 'neither'
- C. 5; 'prime' and 'neither'
- D. 5; 'composite' and 'prime'
Correct answer: A. 5; 'composite' and 'neither'
Decisions: while, if and two conditional expressions, so V(G) = 5 (the loop's else is part of the while decision). g(49) breaks at i = 7, skipping the else, and returns 'composite'. For g(1) the loop never runs, so the else returns 'neither'.
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
- Module ownership: A is known by Ravi and Sita, B by Sita and Aman, C by Aman and Ravi, D by Ravi and Joe. The bus factor is the fewest…
- Intermediate COCOMO for an organic project uses Effort = 3.2 × KLOC^1.05 × EAF person-months. A 30 KLOC system has two non-nominal cost…
- Counting one decision for each loop, if, else-if, && or || operator, case label (not default) and catch clause, what is the cyclomatic…
- For the decision (A or B) and C, which test set (written as A, B, C) achieves MC/DC with only four tests?
- A leap-year function follows the Gregorian rule (divisible by 4, except centuries, unless divisible by 400). Which test set has one year…
- On main, git revert HEAD~3..HEAD is run with no conflicts. What happens?