Algorithm for binary search, Data Structure & Algorithms

Assignment Help:

Q. Write down the algorithm for binary search. Which are the conditions under which sequential search of a list is preferred over the binary search?                                                                   

Ans.

Algorithm for the Binary Search is as follows

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]

Sequential Search is preferred over the binary search when the list is disorder and haphazardly constructed. When searching is to be done on unsorted list then linear search is the only option.


Related Discussions:- Algorithm for binary search

Graphs, c program to represent a graph as an adjacency multilist form

c program to represent a graph as an adjacency multilist form

Sorting, explain quick sort algorithm

explain quick sort algorithm

Algorithms, 2. Write a note on i) devising ii) validating and...

2. Write a note on i) devising ii) validating and iii) testing of algorithms.

Define queue, A queue is a, FIFO (First In First Out) list.

A queue is a, FIFO (First In First Out) list.

Representation of arrays?, A representation of an array structure is a mapp...

A representation of an array structure is a mapping of the (abstract) array with elements of type T onto the store which is an array with elements of type BYTE. The array could be

Signals, How does cpu''s part tming and controls generate and controls sign...

How does cpu''s part tming and controls generate and controls signls in computer?

Mapping constain, one to many one to one many to many many to one

one to many one to one many to many many to one

Memory mapping, lower triangular matrix and upper triangular matrix

lower triangular matrix and upper triangular matrix

Total impedent of the circuit, an electrical student designed a circuit in...

an electrical student designed a circuit in which the impedence in one part of a series circuit is 2+j8 ohms and the impedent is another part of the circuit is 4-j60 ohm mm program

R. Studio, I need a person who has a good background in using R. Studio? I...

I need a person who has a good background in using R. Studio? In adition, a person who is good in using algorithms.

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd