





















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of elementary searching and sorting algorithms, including sequential search, binary search, simple sort, bubble sort, selection sort, and insertion sort. It explains the basic principles, implementations, and big o notation for each algorithm. The document also includes examples and assignments to help understand the concepts. This material is suitable for students learning introductory data structures and algorithms, offering a clear and concise introduction to fundamental concepts.
Typology: Study notes
1 / 29
This page cannot be seen from the preview
Don't miss anything!






















Sequential search Binary search Simple sort Bubble sort Selection sort Insertion sort
Sequential search Binary search
It is natural way of searching The algorithm does not assume that the data is sorted. Algorithm: Search list from the beginning until key is found or end of list reached. Implementation: int i; bool found =false; for(i=0;i<n;i++;) if (DataElement[i]==key) { found=true; break; } return (found);
Algorithm:
Implementation: int Top =n-1, Bottom=0;middle; bool found=false; while (Top>bottom) { Middle=(Top+Bottom)/2; if (dataElement[middle] == key){ found =true; break; } if( dataElement[middle]<key) Bottom=middle+1; else Top=middle; } return found;
In simple sort algorithm, the first element is compared with the second, third, and all subsequent elements. If any of these is less than the current first element then the first element is swapped with that element. The above step is repeated with the second, third and all other subsequent elements.
footer 13
Iteration No. of comparison No. of swaps (compares) 1 st pass n-1 n- 2 nd pass n-2 n-
... ... ... (n-1) th 1 1 Total n(n-1)/2 n(n-1)/ Therefore, Big-O of simple sort algorithm is n(n-1)/2+n(n-1)/2=O(n 2 )
for (i=0; i<=n-2;i++) { min_index=i; for (j=(i+1); j<=n-1;j++) if (dataElement[j] <= dataElement[min_index]) min_index=j; swap (dataElement[i],dataElement[min_index]); }