Algorithm of binary search, Data Structure & Algorithms

Step 1: Declare array 'k' of size 'n' i.e. k(n) is an array which stores all the keys of a file containing 'n' records

Step 2: i←0

Step 3: low←0, high←n-1

Step 4: while (low <= high)do

mid = (low + high)/2

if (key=k[mid]) then

write "record is at position", mid+1   //as the array starts from the 0th position


if(key < k[mid]) then

 high = mid - 1


low = mid + 1




Step 5: Write "Sorry, key value not found"

Step 6: Stop

Posted Date: 4/11/2013 5:20:07 AM | Location : United States

Related Discussions:- Algorithm of binary search, Assignment Help, Ask Question on Algorithm of binary search, Get Answer, Expert's Help, Algorithm of binary search Discussions

Write discussion on Algorithm of binary search
Your posts are moderated
Related Questions
The smallest element of an array's index is called its Lower bound.

Determine in brief the Painter Algorithm a) The farthest polygon, namely the rectangle PQRS, is stored first. (b) The next farthest, the quadrilateral ABCD, is superpo

By taking an appropriate example explain how a general tree can be represented as a Binary Tree.                                                                    C onversio

Question 1 Discuss the following theorems with respect to Splay Trees- Balance Theorem Dynamic Finger Theorem   Question 2 Write a C program for implementation

Write the algorithm for compound interest

Write an algorithm for binary search. What are its limitations? .

merge sort process for an example array {38, 27, 43, 3, 9, 82, 10}. If we take a closer look at the diagram, we can see that the array is recursively divided in two halves till the

Q. Explain the various memory allocation strategies.                                                            Ans. M e m ory Allocation Strategies are given as follow

A binary tree in which if all its levels except possibly the last, have the maximum number of nodes and all the nodes at the last level appear as far left as possible, is called as

Algorithm for determining strongly connected components of a Graph: Strongly Connected Components (G) where d[u] = discovery time of the vertex u throughout DFS , f[u] = f