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

else

if(key < k[mid]) then

 high = mid - 1

else

low = mid + 1

 endif

endif

endwhile

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
Memory Allocation Strategies If it is not desirable to move blocks of due storage from one area of memory to another, it must be possible to relocate memory blocks that have be

Example: Assume the following of code: x = 4y + 3 z = z + 1 p = 1 As we have been seen, x, y, z and p are all scalar variables & the running time is constant irrespective

Determine in brief about the Boolean Carrier set of the Boolean ADT is the set {true, false}. Operations on these values are negation, conjunction, disjunction, conditional,

Time Complexity:- The time complexity of an algorithm is the amount of time it requires to run to completion. Some of the reasons for studying time complexity are:- We may be in

how do we use 4-discs stack to solve tower of hanoi problem and write an algorithm to solve it?

Q. What do you understand by the term sparse matrix? How sparse matrix is stored in the memory of a computer? Write down the function to find out the transpose of a sparse matrix u

Explain the term totalling To add up a series numbers the subsequent type of statement must be used: Total = total + number  This literally means (new) total = (old) t

Implement a linear-expected-time algorithm for selecting the k th smallest element Algorithm description 1. If |S| = 1, then k = 1 and return the element in S as the an

Range: A Structured Type in Ruby Ruby has a numerous structured types, comprising arrays, hashes, sets, classes, streams, and ranges. In this section we would only discuss rang

#questionalgorithm for implementing multiple\e queues in a single dimensional array