Algorithm for finding a key by binary search technique, Data Structure & Algorithms

Q. Write down an algorithm for finding a key from a sorted list using the binary search technique or method.                                                                                                                      

Ans.

Binary Search Algorithm is written below

1.   if (low > high)

2.     return (-1)

3.    mid = (low +high)/2;

4    .if ( X = = a [mid])

5     return (mid);

6     if ( X < a [mid])

7    search for X in a (low) to [mid -1];

8    else

9     search for X in a [mid + 1] to a [high];

 

 

Posted Date: 7/13/2012 2:18:04 AM | Location : United States







Related Discussions:- Algorithm for finding a key by binary search technique, Assignment Help, Ask Question on Algorithm for finding a key by binary search technique, Get Answer, Expert's Help, Algorithm for finding a key by binary search technique Discussions

Write discussion on Algorithm for finding a key by binary search technique
Your posts are moderated
Related Questions
the voltage wave forms are applied at the inputs of an EX-OR gate. determine the output wave form

what happen''s in my computer when i input any passage

PART- Pest Control Program Prepare a Pest Control Program for the facility that will address the management of Rodents, Insects and Birds. Your Pest Control Program should

Write an algorithm using pseudocode which takes temperatures input over a 100 day period (once per day) and output the number of days when the temperature was below 20C and the num

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

Question: (a) Discuss the importance of game theory to decisions. (b) Explain the following: (i) saddle point, (ii) two-person zero-sum game. (c) Two leading ?rms, ABC Ltd a

The Linked list is a chain of structures wherein each structure contains data in addition to pointer, which stores the address (link) of the next logical structure in the list.

In the array implementation of lists, elements are stored into continuous locations. In order to add an element into the list at the end, we can insert it without any problem. But,

A Sort which relatively passes by a list to exchange the first element with any element less than it and then repeats with a new first element is called as      Quick sort.

how I can easily implement the bubble,selection,linear,binary searth algorithms?