BinarySearch is called on the array below, searching for Value 20. Is the final value of Index 20 in [6]. I think this is right.

2 5 10 15 20 20 20 20
[1] [2] [3] [4] [5] [6] [7] [8]

Recommended Answers

All 2 Replies

Array index starts with 0 & there is a total of 8 elements. So, the first no to be checked is (7-0)/2 = [3]. The second is 3+(7-3)/2 = [5].

Thank you Prabakar

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.