954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

BinarySearch

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]

buddy1
Newbie Poster
17 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

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].

Prabakar
Posting Whiz
342 posts since May 2008
Reputation Points: 94
Solved Threads: 33
 

Thank you Prabakar

buddy1
Newbie Poster
17 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You