what is the complexity of a program having only one loop, is it log n? can someone give me some ideas about estimating complexity of codes?
If there's just one loop, it's probably the number of times that loop's body executes.... But of course you may have many hidden loops in library calls. It's easy to make a loop that executes n
times O(n^2)
or worse if you have strlen
, memcpy
, etc. taking place inside the loop body.
Or even worse, if you have a library (or language) with regular expressions and their regex implementation is naive (like Perl), it's easy to make a program with just a single loop O(2^n)
!! This cannot happen with a correctly written regex implementation.