Computer Science, asked by hala8896, 1 year ago

Write a program in c++ to read an array of sorted integers search for a value using binary search method if the elements is found, print its location else print element not found

Answers

Answered by aqibkincsem
2

"The recursive version is that,

Binary search( a(0,n-1), low, high, value)

{

if(low>high)

Then,

Return-1;

---not found---

Mid=(high-low)+low/2;

If(value<a(mid))

Then

Return binary search(value, mid+1,high, a);

Else

Return mid

----found----

{

You must keep on going until the key given here matches the mid point and them you get your code executed.

First, we must initialize, followed by getting to the mid point and then we must adjust both upper and lower limits and finally we must compare them to get successfully executed."

Similar questions