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

Ask consider the file name cars.text each line in the file contains information about a car ( year,company,manufacture,model name,type) 1-read the file 2-add each car which is repr

Q. Let a binary tree 'T' be in memory. Write a procedure to delete all terminal nodes of the tree.       A n s . fun ction to Delete Terminal Nodes from Binary Tree

There are ten stations on a railway line: Train travels in both directions (i.e. from 1 to 10 and then from 10 to 1).  Fare between each station is $2. A passenger input

What are the features of an expert system

write an algorithm for multiplication of two sparse matrices using Linked Lists

Illustrate the intervals in mathematics Carrier set of a Range of T is the set of all sets of values v ∈ T such that for some start value s ∈ T and end value e ∈ T, either s ≤

write an algorithm for stack using array performing the operations as insertion ,deletion , display,isempty,isfull.

Q. Prove the hypothesis that "A tree having 'm' nodes has exactly (m-1) branches".      Ans: A tree having m number of nodes has exactly (m-1) branches Proof: A root