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
Preorder traversal of a binary tree struct NODE { struct NODE *left; int value;     /* can take any data type */ struct NODE *right; };   preorder(struct N

Q. Explain quick sort? Sort the given array using quick sort method. 24 56 47 35 10 90 82 31

Q. Explain the result of inserting the keys given. F, S, Q, K, C, L, H, T, V, W, M, R, N, P, A, B, X, Y, D, Z, E  in an order to an empty B-tree of degree-3.

Algorithm for insertion of any element into the circular queue: Step-1: If "rear" of the queue is pointing at the last position then go to step-2 or else Step-3 Step-2: make

A LGORITHM (Deletion of an element from the linked list) Step 1  Begin Step 2  if the list is empty, then element cannot be deleted Step 3  else, if the element to be del

The objective analysis of an algorithm is to determine its efficiency. Efficiency is based on the resources which are used by the algorithm. For instance, CPU utilization (Ti

I need a recursive algorithm to implement the FIRST function to any grammar

Any binary search tree must contain following properties to be called as a red-black tree. 1. Each node of a tree should be either red or black. 2. The root node is always bl

Complexity classes All decision problems fall in sets of comparable complexity, called as complexity classes. The complexity class P is the set of decision problems which ca

Define order of growth The  efficiency  analysis  framework  concentrates   on  the  order  of  growth  of  an  algorithm's   basic operation count as the principal indicator o