The following is a piece of python code:
sum=0
for i in range(1,f(n)+1):
sum=sum+i

f(n) is a function call. I need to find a tight big oh upper bound for the time taken by the above written piece of code in the following cases:
1. when the time taken for execution of f(n) is O(n) and f(n) is n factorial.
2. when the time taken for execution of f(n) is O(n) and f(n) is n
3. when the time taken for execution of f(n) is O(n^2) and f(n) is n
4. when the time taken for execution of f(n) is O(1) and f(n) is 0
Please tell me step by step how to solve this..please reply as soon as possible..
I'll be really thankful!!:?:

Pretty much you just have to count how many instructions get run and convert that to O notation.

With all due respect, I want to tell you that I'm completely new to this..i would really appreciate and would be really thankful if you tell me the answers as well so that i can verify that the way i've solved this question is correct..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.