Write an algorithm for binary search., Data Structure & Algorithms

Write an algorithm for binary search.

Algorithm for Binary Search

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 a[mid-1]
8.  else
9.  search for X in a[mid+1] to a[high] 

Posted Date: 5/10/2013 5:14:26 AM | Location : United States







Related Discussions:- Write an algorithm for binary search., Assignment Help, Ask Question on Write an algorithm for binary search., Get Answer, Expert's Help, Write an algorithm for binary search. Discussions

Write discussion on Write an algorithm for binary search.
Your posts are moderated
Related Questions
Explain in brief about the Container An entity which holds finitely many other entities. Just as containers such as boxes, baskets, bags, pails, cans, drawers, and so for

What are the expression trees? Represent the below written expression using a tree. Give a relevant comment on the result that you get when this tree is traversed in Preorder,

In this section, we will discuss about Sequential file organization. Sequential files have data records stored in a particular sequence. A sequentially organized file might be stor

In a chained hash table, each table entry is a pointer to a collection of elements. It can be any collection that supports insert, remove, and find, but is commonly a linked list.

Write a program to create a heap file that holds the records in the file " data_2013 " The source records are variablelength.However, the heap file should hold fixed-length reco

In-order Traversal  This process when executed iteratively also needs a stack and a Boolean to prevent the implementation from traversing any portion of a tree twice. The gener

Example: (Single rotation into AVL tree, while a new node is inserted into the AVL tree (LL Rotation)) Figure: LL Rotation The rectangles marked A, B & C are trees

A town contains a total of 5000 houses. Every house owner has to pay tax based on value of the house. Houses over $200 000 pay 2% of their value in tax, houses over $100 000 pay 1.

INSERT FUNCTION /*prototypes of insert & find functions */ list * insert_list(list *); list * find(list *, int); /*definition of  anyinsert function */ list * inser

What is Efficiency of algorithm? Efficiency of an algorithm can be precisely explained and investigated with mathematical rigor.  There are two types of algorithm efficiency