Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Data File StructureRSS Feeds

Algorithms of sequential search and binary search

Posted By: Zachary Evans     Category: C++ Programming     Views: 9413

This article provides an algorithm of sequential search and binary search.

Algorithm for Sequential Search

1.  Initialize searcharray, searchno, length.

2.  Initialize pos=0.

3.  Repeat step 4 till pos<=length.

4.  if searcharray[pos]=searchno
        return pos
    else
        increment pos by 1.

Algorithm for Binary Search

1.  Initialize an ordered array, searcharray, searchno, length.

2.  Initialize low=0 and high=length.

3.  Repeat step 4 till low<=high.

4.  Middle =(low + high) / 2.

5.  if searcharray[middle]=searchno
        Search is successful
        return middle.
    else if searcharray[middle]>searchno[high]
        high=middle - 1
    else
        low=middle + 1.



  
Share: 


Didn't find what you were looking for? Find more on Algorithms of sequential search and binary search Or get search suggestion and latest updates.

Zachary Evans
Zachary Evans author of Algorithms of sequential search and binary search is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!