CS FundamentalsVery hardProduct-company placement
What is the cyclomatic complexity of this function, counting each simple condition separately and each loop header as one decision?
What is the cyclomatic complexity of this function, counting each simple condition separately and each loop header as one decision?
def classify(nums):
pos = neg = 0
i = 0
while i < len(nums):
n = nums[i]
if n > 0 and n % 2 == 0 or n > 100:
pos += 1
elif n < 0:
neg += 1
i += 1
return pos, neg- A. 4
- B. 3
- C. 6
- D. 1
Correct answer: C. 6
Decisions: while (1), the compound condition with three simple conditions (3) and elif n < 0 (1) = 5, so V(G) = 6. Counting the compound condition once gives 4, counting the three statements without the + 1 gives 3, and 1 treats the function as a single path.
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
- A team wants its HTTP API to allow safe retries of PUT /users/42 with the full user body. Which property of PUT makes this safe, and what…
- Putnam's software equation implies that, for a fixed size and process productivity, effort varies as 1/t^4, where t is the development…
- A project has BAC = ₹500 lakh, PV = ₹240 lakh, EV = ₹200 lakh and AC = ₹250 lakh. If both cost and schedule performance are expected to…
- Last sprint, 6 developers working 10 days completed 30 story points. Next sprint 5 developers are available for 9 days each. Using the…
- A single-server queue (M/M/1) serves 10 requests per second. At 8 requests/s the mean response time W = 1/(μ - λ) is 0.5 s. What happens…
- 90% of a CI pipeline's run time is parallelisable tests and 10% is serial setup. Moving to 8 parallel runners, what overall speed-up does…