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
what''s queue ?

Program: Program segment for insertion of an element into the queue add(int value) { struct queue *new; new = (struct queue*)malloc(sizeof(queue)); new->value = val

W h at are the different ways by which we can represent graph?  Represent the graph drawn below using those ways.     T he d iff e r e nt w a y s by

explain two strategies to implement state charts with the help of an example of each.

an electrical student designed a circuit in which the impedence in one part of a series circuit is 2+j8 ohms and the impedent is another part of the circuit is 4-j60 ohm mm program

Illustrate the Visual realism applications a)   Robot Simulations : Visualization of movement of their links and joints  and end effector movement etc. b)  CNC programs ver

explain quick sort algorithm

differentiate between indexing and hashing in file organization

Define an array. Array is made up of same data structure that exists in any language. Array is set of same data types. Array is the collection of same elements. These same elem

A representation of an array structure is a mapping of the (abstract) array with elements of type T onto the store which is an array with elements of type BYTE. The array could be