CS FundamentalsVery hardProduct-company placement
For the function below, what is its cyclomatic complexity, and how many times is a[i] + a[j] == target evaluated for findpair([1, 2, 3, 4, 5], 9)?
For the function below, what is its cyclomatic complexity, and how many times is a[i] + a[j] == target evaluated for find_pair([1, 2, 3, 4, 5], 9)?
def find_pair(a, target):
for i in range(len(a)):
for j in range(i + 1, len(a)):
if a[i] + a[j] == target:
return (i, j)
return None- A. V(G) = 4; 10 evaluations
- B. V(G) = 3; 10 evaluations
- C. V(G) = 4; 20 evaluations
- D. V(G) = 4; 9 evaluations
Correct answer: A. V(G) = 4; 10 evaluations
Two loop headers and one if make 3 decisions, so V(G) = 4. Pairs are checked in order (0,1)…(0,4), (1,2)…(1,4), (2,3), (2,4), (3,4); the match 4 + 5 is the 10th check, the last pair.
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
- For the same findpair function (two nested for loops, an if that returns (i, j) when a pair matches, and return None after the loops)…
- A Value Object is modelled as a frozen dataclass. What does this print? python from dataclasses import dataclass, FrozenInstanceError…
- This Singleton caches its instance in new. What does it print? python class Settings: instance = None def new(cls, args): if cls.instance…
- Module report.py does from pricing import getrate and calls getrate() inside build(). A unit test for build() uses…
- A faulty merge M of feature into main was undone with git revert -m 1 M. The feature team later fixes the bug with a new commit on feature…
- You run git stash pop and it reports a merge conflict in f.txt. What happens to the stash entry?