Usually the rule is that if there is a loop of 1 to n elements then the complexity is O(n), and further nested loops are n x O(n). However, when do we say if a subroutine has complexity O(log n)?
            Asked
            
        
        
            Active
            
        
            Viewed 297 times
        
    -1
            
            
        - 
                    Check: http://stackoverflow.com/a/16785817/2128327 – Khaled.K May 28 '13 at 07:10
- 
                    No need to downvote my question... – Evil Washing Machine May 28 '13 at 16:21
2 Answers
1
            
            
        You can take as first example binary search. A explanation of the complexity of this algorithm can be taken from a related question how to calculate binary search complexity. It shown that the calculation of this type of complexity can be obtain from the recurrence.
1
            When in each iteration we reduce the problem size be a factor of X , we can say that the problem is O(log n)
E.g - Binary Search: in each iteration we reduce the problem size by factor of 2
 
    
    
        Mzf
        
- 5,210
- 2
- 24
- 37
 
     
    