1
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

4
  • What do you mean by "matching construct"? Also, shouldn't if(ret = false) be if(ret == false), or perhaps better if (! ret)? Commented Jul 20, 2022 at 7:46
  • I don’t know what to tell you since my university professor gave it as a track to be converted into an iterative version Commented Jul 20, 2022 at 7:49
  • Sorry I have no idea how to interpret this. You said "I can’t understand the meaning of that OR without any matching construct.". What is a "matching construct"? How would it help you? Can you give an example? Commented Jul 20, 2022 at 8:03
  • @n.1.8e9-where's-my-sharem. probably means, semantic of that operator? Commented Jul 20, 2022 at 8:03

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.