0

I understand how to do the for loop but a while with two statements i am not sure.

while ( i >0 and x< A[i-1])

maybe break it down into two if statements?

if i>0
   if x<A[i-1]

but how do i find the best and worst case in terms of n here?

Conduit
  • 2,675
  • 1
  • 26
  • 39
gds hgff
  • 1
  • 1

1 Answers1

0

while ( i >0 and x< A[i-1])
"maybe break it down into two if statements?"

Yes you can do this

while(true) {
    if(i > 0) {
        if(x < A[i-1]) {
            // break; or continue; here, whatever your logic actually needs
        }
    }
}
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190