Ask Your Question
3

What is the time complexity of this code when it includes a conditional statement?

asked 2023-02-07 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-08-25 08:00:00 +0000

lakamha gravatar image

The time complexity of a code with a conditional statement depends on the whether the condition is true or false, as well as the complexity of the code inside the condition. If the condition is true and the code inside the condition has a time complexity of O(f(n)), and the code outside the condition has a time complexity of O(g(n)), then the overall time complexity of the code would be O(max(f(n), g(n))). If the condition is always false, then the complexity would simply be O(g(n)), the time complexity of the code outside the condition. Alternatively, if the condition is always true, then the complexity would be O(f(n)), the time complexity of the code inside the condition.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-02-07 11:00:00 +0000

Seen: 9 times

Last updated: Aug 25 '21