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






Your posts are moderated
Related Questions
Consider the following 5-city traveling salesman problem. The distance between each city (in miles) is shown in the following table: (a) Formulate an IP whose solution will

Full Binary Trees: A binary tree of height h that had 2h -1 elements is called a Full Binary Tree. Complete Binary Trees: A binary tree whereby if the height is d, and all of

Q. Give the adjacency matrix for the graph drawn below:                                                 Ans: Adjacency matrix for the graph given to us

Algorithm for determining strongly connected components of a Graph: Strongly Connected Components (G) where d[u] = discovery time of the vertex u throughout DFS , f[u] = f

What is an unreachable code assertion An unreachable code assertion can be placed at the default case; if it's every executed, then program is in an erroneous state. A loop in

Q. Describe the basic concept of binary search technique? Is it more efficient than the sequential search?         Ans : The bin ary search technique:- This tec

The information in the table below is available for a large fund-raising project. a. Determine the critical path and the expected completion time of the project. b. Plot the total

Example: (Double left rotation while a new node is added into the AVL tree (RL rotation)) Figure: Double left rotation when a new node is inserted into the AVL tree A

Assertions and Abstract Data Types Even though we have defined assertions in terms of programs, notion can be extended to abstract data types (which are mathematical entities).

Technique for direct search is    Hashing is the used for direct search.