int L=A.length-1;
int index=(L-1)/2;

int k=2*index+1;
            if(A[k]<A[k+1]) k=k+1;}
            int t=A[index];
        }else break;
  • $\begingroup$ Are you asking us to do your homework for you? Because it looks like you're asking us to do your homework for you. $\endgroup$ – Turksarama Dec 16 '19 at 1:47
  • 2
    $\begingroup$ What did you try? Where did you get stuck? We're happy to help you understand the concepts but just solving exercises for you is unlikely to achieve that. You might find this page helpful in improving your question. $\endgroup$ – D.W. Dec 16 '19 at 2:13

I think your code tries to do heap sorting. Im saying "tries" because youre missing some code.

If you want to know the complexity of the entire algorithm then here it is: Best case: n* log(n) Worst case: nlog(n) Average: nlog(n)

Where log(n) is the logarithm of n in base 2.

But if youre interested in only the complexity of YOUR while, then it is: Best case: log(n) Worst case: log(n) Average: log(n)

If you want to read more about heaps, try some youtube videos, the wikipedia link, or this link : https://www.geeksforgeeks.org/time-complexity-of-building-a-heap/

Please vote my answer if i helped you.

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.