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
Give example of assertion and abstract data type For illustration, consider Natural ADT whose carrier set is the set of non-negative integers and whose operations are the usual

State about the Simple types - Built-In Types Values of the carrier set are atomic, that is, they can't be divided into parts. Common illustrations of simple types are inte

A striking application of DFS is determine a strongly connected component of a graph. Definition: For graph G = (V, E) , where V refer to the set of vertices and E refer to the

Data array A has data series from 1,000,000 to 1 with step size 1, which is in perfect decreasing order. Data array B has data series from 1 to 1,000,000, which is in random order.

Simplifying Assumptions of wire frame representation Neglect colour - consider Intensity: For now we shall forget about colour and restrict our discussion just to the intensi

Searching is the procedure of looking for something. Searching a list containing 100000 elements is not the similar as searching a list containing 10 elements. We discussed two sea

The operations of the Symbol ADT The operations of the Symbol ADT are the following. a==b-returns true if and only if symbols a and bare identical. a symbol bin Unico

Write down any four applications of queues.            Application of Queue (i)  Queue is used in time sharing system in which programs with the similar priority form a queu

After going through this unit, you will be able to: • define and declare Lists; • understand the terminology of Singly linked lists; • understand the terminology of Doubly