Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.