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
How memory is freed using Boundary tag method in the context of Dynamic memory management? Boundary Tag Method to free Memory To delete an arbitrary block from the free li

What is the difference between a grounded header link list and a circular header link list? A header linked list is a linked list which always having a special node, known as t


Threaded Binary Tree:- By changing the NULL lines in a binary tree to special links known as threads, it is possible to perform traversal, insertion and deletion without using

Differentiate between Nonpersistent and 1-persistent Nonpersistent: If the medium is idle, transmit; if the medium is busy, wait an amount of time drawn from a probability dist

Q. Describe what do you understand by the term array? How does an array vary from an ordinary variable? How are the arrays represented in the specific memory?

explain collision resloving techniques in hasing

write a pseudocode to input the top speed (in km''s/hours) of 5000 cars output the fastest speed and the slowest speed output the average (mean) speed of all the 5000 cars answers

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

Explain the bubble sort algorithm. Answer This algorithm is used for sorting a list. It makes use of a temporary variable for swapping. It compares two numbers at an insta