time complexity - What is the Difference in the Big-Oh of these Loops? -


the 3 loops:

three loops

i'm new big-oh stuff , i'm having difficulty seeing difference in complexity between these 3 loops.

they seem run less o(n^2) more o(n).

could explain me how evaluate complexity of these loops?

thanks!

could explain me how evaluate complexity of these loops?

start defining problem. linked image has little go on, let's start making stuff:

  • the parameter being varied integer n.
  • c constant positive integer value greater one.
  • the loop variables integers
  • integers not overflow
  • the costs of addition, comparison, assignment, multiplication , indexing constant.
  • the cost looking find complexity of cost of constant operations of innermost loop; ignore additions , whatnot in actual computations of loop variables.
  • in each case innermost statement same, , of constant cost, let's call cost "one unit" of cost.

great.

what cost of first loop?

the cost of inner statement 1 unit.

the cost of "j" loop containing ten units every time.

how many times "i" loop run? n divided c times.

so total cost of "i" loop 10 * n / c, o(n).

now can second , third loops? more running trouble. start with:

  • the cost of first run of "j" loop 1 unit.
  • the cost of second run of "j" loop c units
  • the cost of third run of "j" loop c * c units
  • ...

and go there.

remember don't need work out exact cost function. need figure out dominating cost. hint: know c * c * c ... @ last run of outer loop?


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -