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
Write an algorithm for multiplication of two sparse matrices using Linked Lists.

Q. Define a method for keeping two stacks within a single linear array S in such a way that neither stack overflows until entire array is used and a whole stack is never shifted to

A binary tree is a tree data structures in which each node have at most two child nodes, generally distinguished as "right" and "left". Nodes with children are called parent nodes,

Q. Make the 11 item hash table resulting from hashing the given keys: 12, 44, 13, 88, 23, 94, 11, 39, 20, 16 and 5 by making use of the hash function h(i) = (2i+5) mod 11.

We would like to implement a 2-4Tree containing distinct integer keys. This 2-4Tree is defined by the ArrayList Nodes of all the 2-4Nodes in the tree and the special 2-4Node Root w

In a doubly linked list, also called as 2 way list, each node is divided into 3 parts. The first part is called previous pointer field. It contains the address of the preceding

By taking an appropriate example explain how a general tree can be represented as a Binary Tree.                                                                    C onversio

Comparison of Gouraud and Phong Shading Phong shading requires more calculations, but produces better results for specular reflection than Gouraud shading in the form of more r

What is the best case complexity of quick sort In the best case complexity, the pivot is in the middle.

Explain All-pair shortest-paths problem Given a weighted linked graph (undirected or directed), the all pairs shortest paths problem asks to find the distances (the lengths of