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?
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?
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
}
}
}