answersLogoWhite

0

1. //ALGORITHM:Bin search(a,i,l,x).

2. //given an array a(i,l) of elements in non-decreasing.

3.// order,1<=i<=l,determine wether x is present and

4. //if so,return j such that x=a[j],else return 0.

5. {

6. if(l=i) then

{

if(x=a[i] then return i;

else return 0;

}

else

{

mid=[(i+l)/2]

if(x-a[mid] then return mid

else if(x<a[mid]) then

return Bin search(a,i,mid-1,x)

else return Bin search(a.mid+1,l,x)

}

}

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

How can you merge two binary search trees into a single binary search tree?

To merge two binary search trees into a single binary search tree, you can perform an in-order traversal on each tree to extract their elements, combine the elements into a single sorted list, and then construct a new binary search tree from the sorted list. This process ensures that the resulting tree maintains the binary search tree property.


What is the process of traversing a binary tree level by level, starting from the root node, known as?

The process of traversing a binary tree level by level, starting from the root node, is known as breadth-first search (BFS).


What assumption about the list is made when binary search is conducted?

Binary search requires that the list be in search key order.


What is the use of binary?

Binary trees are commonly used to implement binary search tree and binary heaps.


A binary search of an orderd set of elements in an array or a sequential search of the elements.Which one is faster?

A binary search is much faster.


What is the binary number for decimal 191?

It is 10111111 in binary. Try a search for '191 to binary'.


Does binary tree and binary search tree same?

no they are not same


Items that are not suitable for a binary search?

The only items suitable for a binary search are those which are in a sorted order.


Are binary search trees always balanced?

No, binary search trees are not always balanced. Balancing a binary search tree involves ensuring that the height difference between the left and right subtrees of each node is at most 1. Unbalanced binary search trees can lead to inefficient search and insertion operations.


What are the drawbacks of the binary search?

The only drawback I know of is that binary search requires that the list already be sorted. So if you have a really large unsorted list than binary search would not be the best option.


How do you print all data in a Binary Search Tree?

By using Depth First Search or Breadth First search Tree traversal algorithm we can print data in Binary search tree.


What is complexity of binary search tree?

The complexity of binary search tree : Search , Insertion and Deletion is O(h) . and the Height can be of O(n) ( if the tree is a skew tree). For Balanced Binary Trees , the Order is O(log n).