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 data structure needed for Breadth First Traversal on a graph is Queue

Write a recursive function the computes the number of digits in a positive integer n. For example if n = 6598, the function should return 4. Find a variant expression and a thresho

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

If preorder traversal and post order traversal is given then how to calculate the pre order traversal. Please illustrate step by step process

Program gives the program segment by using arrays for the insertion of an element to a queue into the multiqueue. Program: Program segment for the insertion of any element to t

Spanning Trees: A spanning tree of a graph, G, refer to a set of |V|-1 edges which connect all vertices of the graph. There are different representations of a graph. They are f

explain the prims''s algorithm with suitable example?

Enumerate about the concept of container A Container can have a size() operation. We can also ask (somewhat redundantly) whether a Container is empty. And even though a Contain

Example: (Double left rotation while a new node is added into the AVL tree (RL rotation)) Figure: Double left rotation when a new node is inserted into the AVL tree A

1. develop an algorithm which reads two decimal numbers x and y and determines and prints out wether x>y or y>x. the input values, x and y, are whole number > or equal to 0, which