O-Kalkül einer if-else Anweisung?
Moin,
angenommen ich habe eine if-else in folgender Form:
if <Bed A>:
<Anweisungsfolge B>
else:
<Anweisungsfolge C>
Wäre die Komplexität dann mit O(max(A),max(B),max(C)) zu bestimmen? Oder mit O(max((A*B),(C*B)))?
Im Worstcase würde die Bedingung der if (z.B. wenn in dieser ein anderer Algorithmus aufgerufen wird) ja immer durchlaufen. Egal ob am Ende Anweisungsfolge B oder C durchgeführt wird.
Danke für eure Hilfe 🙂
O(A+B+C) if both branches can be run through.
When thinking more closely, it makes absolutely sense, thank you 😀
If the condition A has, for example, n passages, but instruction sequence B n^2 would be followed by O(n^2) in the constellation at n^2+n passages.
Thanks for the help!
:-
A+max(B,C)
And max(B,C) can You then replace directly with the larger of the two branches.