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
Explain the halting problem Given a computer program and an input to it, verify whether the program will halt on that input or continue working indefinitely on it.

Q. Implement a stack making use of the linked list. Show the PUSH and POP operations both. A n s . Stack implemantation using linked list # include # include

Q. Can a Queue be represented by circular linked list with only one pointer pointing to the tail of the queue? Substantiate your answer using an example. A n s . Yes a

The quick sort algorithm exploit design technique Divide and Conquer

how to write prims algorithms? with example

Which of the sorting algorithm is stable   Heap sorting is stable.

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.

Warnock's Algorithm A divide and conquer algorithm Warnock (PolyList PL, ViewPort VP) If (PL simple in VP) then Draw PL in VP, else Split VP vertically and horiz

Suppose that you want to develop a program that accepts a postfix expression and asks values for variables in the expression. Then you need to calculate the answer for the expressi

Approximating smooth surfaces with Polygon nets Networks of polygons are used to represent smooth surfaces. They are, of course, only an approximation to the true surface, but