Home > Back-end >  Understanding operation algorithm for PseudoCode
Understanding operation algorithm for PseudoCode

Time:07-20

Algo(A,p,r,k)
  ret = false
  if(p <= r) then
    if(p = r) then
      ret = (k == A[p])
    else
      q = (p r)/2
      ret = (k == A[q]) || Algo(A,p,q - 1,k)
      if(ret = false)
        ret = Algo(A,q 1,r,k)
 return ret

please explain to me what operation it does in line 11 ret = (k == A[q]) || Algo(A,p,q - 1,k)?? I can’t understand the meaning of that OR without any matching construct.

thanks in advance

CodePudding user response:

Usually (but you need to check what your teacher is able to say), || is a short-cut or operator. Short-cut in the sense that (for or) if the left expression is true then you don't have to evaluate the right one because you can deduce the result of the full boolean expression.

  • Related