#Help me understand time complexity algorithms

9 messages · Page 1 of 1 (latest)

prime oxide
#

I understand the first statement depends on how many n there is, as it will loop until n so O(n).

I understand the second one is just 1 process regardless of n so its O(1).

The third i am still not understanding but i assume since one loop is dependent on n, nested in another n that it will be o(n²)

However, i dont understand how to get for example 2n+1 for the calculations for the first one. I dont understand how the second one is 2. How do i calculate this? Thank you.

cunning forumBOT
#
  1. Wait patiently for a helper to come along.
  2. Once someone helps you, say thank you and close the thread with:
+close
  1. Feel free to nominate the person for helper of the week in #helper-nominations
  2. Do not ping the mods, unless someone is breaking the rules.
  3. If you're happy with the help you got here, and the server overall, you can contribute financially as well:
near ember
#

Think about sums to calculate complexity.

#

For example, for the first one, you do $\sum_{i=1}^n c = nc = O(n)$, with $c$ the time constant for assignment.

pine graniteBOT
near ember
#

Now, try to determine big O of the 3rd one.

#

However, i dont understand how to get for example 2n+1 for the calculations for the first one. I dont understand how the second one is 2. How do i calculate this?

pine graniteBOT