I have problem at hand which can be solved in the following two ways.
if(...) //First if statement
for( i = 0; i < n; i++ ) //Loop over n elements
{ ... } //Some statement; Time Complexity O(1)
if(...) //Second if statement
for( i = 0; i < n; i++ ) //Loop over n elements
{ ... } //Some statement; Time Complexity O(1)
if(...) //Third if statement
for( i = 0; i < n; i++ ) //Loop over n elements
{ ... } //Some statement; Time Complexity O(1)
or by having 3 ifs in the same loop, like this..
for( i = 0; i < n; i++ ) //Loop over n elements
if(...) //First if statement
{ ... } //Some statement; Time Complexity O(1)
if(...) //Second if statement
{ ... } //Some statement; Time Complexity O(1)
if(...) //Third if statement
{ ... } //Some statement; Time Complexity O(1)
Now the asymptotic time complexity, should be same in both the cases O(3n) as the asymptotic time complexity of the loop is O(n) and asymptotic time complexity of each if statement is O(1).
So my question is, which is the better way to implement the solution and why ?
Please note, I am not concerned about the asymptotic space complexity.