I am estimating the worst-case time complexity of this piece of code:
if (condition) {
// loop over A
} else {
// loop over B
}
such that A and B are disjoint sets and |A| + |B| = C. In my opinion, the worst-case time complexity is O(max(|A|, |B|)) = O(C). Could you please tell me if it is correct?
Also a side question, if I have a complexity like O(N(1 + M)), do I have the right to drop 1 and keep only O(NM) as the final complexity?
I apologize if my question is too basic. I haven't touched complexity analysis for a long time.
Thank you!
I am guessing that it may depend on the condition, and some probabilities of A and B hitting the condition. For example, if the condition is
A.length > B.lengththen it would beO(max(|A|, |B|).Also for your side question, you definitely can drop the
Nin theO(N(1+M))to have the final beO(NM).