P
P
Philip Polikarenkov2016-11-18 13:44:49
C++ / C#
Philip Polikarenkov, 2016-11-18 13:44:49

How to write an algorithm for binary search on an array with C numbers?

I want to write an algorithm myself, without peeping, but I can’t figure out how to get the array indices. Those. here we have an array, its size is 500 cells, we take the 250th cell, find out that the desired value is to the right. Accordingly, the search area is now from 250 to 500, and the size of the second half is 250. You can copy the second half of the array to another array and then the indices will start from zero, but then what's the point of a binary search?
Give me an idea please. How can I get the correct array indexes?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MiiNiPaa, 2016-11-18
@Vilibb

What does faithful mean? Do you want an index in the middle of the new search area? start + (end - start)/2, primitive math.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question