Searching & Sorting

Searching and sorting are two most important operations that are frequently performed on data structures. These are fundamental operations in computer science . These are mostly performed on data structures like arrays , linked lists and trees .

Searching :

The process of finding a specific data item or record from a list is called searching . The search is successful if the specified data item or record is found during searching process. Search operation terminates when it is successful.If the specified data is not found then the search is unsuccessful.Different techniques are used to carry out search operations . The commonly used searching methods are .

  •  Sequential Search
  •  Binary Search

Sequential Search:

The sequential search is a simple and straightforward technique to search a specified item in an unordered list.The specified value is searched in the list sequentially ,i.e. starting from the first element to the last element in the list in a sequence . When the required value is found , search operation stops .

Write a program that search the number in an array using sequential search : 

using namespace std;
int main(){                                                                                                                       int array[5]={2,3,4,1,6};                                                                                                          int loc=0;
int num;
cout<<“Enter a number  : ” ;

for(int j=0;j<5;j++)                                                                                                               if(array[j]==num){
cout<<“Data found “;
break; }
cout<<“Data not found “;
return 0;

One Reply to “Searching & Sorting”

Leave a Reply

Your email address will not be published. Required fields are marked *