Ask Question
14 October, 01:09

When using the BinarySearch () method of an array or list type, what value is returned when the element is not found? How can we decode this value and make use of it?

+2
Answers (1)
  1. 14 October, 04:37
    0
    When the element is not found we return - 1.

    Explanation:

    When we use binary search we use BinarySearch () method of an array or list type when the element is found we return the index of the element if found if the element is not found we return - 1.

    We can decode this value since it is less than 0 and the indexing of arrays and lists starts with 0 upto the size-1. So - 1 index is not present in the array or list. We have to check if the index is < 0 then the element is not present in the array or list.

    for ex:-

    if (index<0)

    {

    System. out. println ("Element is not present in the array");

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “When using the BinarySearch () method of an array or list type, what value is returned when the element is not found? How can we decode ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers