0

I am looking for the time complexity (big O) for the following nested loop. Given an array A[] with size n.

for (i=1; i<=n/2; i++){
    for(j=i; j<=n-i; j++){
        print (A[j]);
    }
}

In this problem A is indexed at 1. so the first element of A[] is A[1].

1 Answer 1

2

Since the innermost execution time is constant, we have enter image description here

So T(n) is O(n^2)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.