Logo 
Search:

C++ Programming FAQ

Submit Interview FAQ
Home » Interview FAQ » C++ ProgrammingRSS Feeds

Write an algorithm for Binary Search in dfs (data file structure).

  Shared By: Adelisa Fischer    Date: Jul 05    Category: C++ Programming    Views: 3236

Answer:

1. Initialize an ordered array, searcharray, searchno, length.

2. Initialize low=0 and high=length.

3. Repeat step 4 till low<=high.

4. Middle =(low + high) / 2.

5. if searcharray[middle]=searchno
Search is successful
return middle.
else if searcharray[middle]>searchno[high]
high=middle - 1
else
low=middle + 1.

Share: 
 


Related Topics:

Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].


Tagged: