find time complexity for the given program.

Find the complexity of the program below.

function(int n){
    if(n == 1) return;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            printf("*");
            break;
        }
    }
}
3Comments
dk @dkbhatt
9 Sep 2017 09:47 am

O(n)

Ravi Raj Singh @ravirajsingh
9 Sep 2017 08:07 pm

O(n)

shivani @shivani1234
25 Sep 2017 04:51 pm
O(n) instead of O(n*n) because of the presence of 'break' in inner loop due to which inner loop is executed only once for every outer loop.