Searching Sorting Algorithms
Searching Sorting Algorithms
What is Searching?
Searching is the process of finding a specific element (called the key) in a data structure like an array or list.
1. Linear Search:
C++ Example:
if(arr[i] == key)
return i;
return -1;
2. Binary Search:
C++ Example:
return -1;
}
3. Jump Search:
4. Interpolation Search:
5. Exponential Search:
What is Sorting?
1. Bubble Sort:
C++ Example:
swap(arr[j], arr[j+1]);
2. Selection Sort:
4. Merge Sort:
5. Quick Sort:
6. Heap Sort:
7. Radix Sort:
Conclusion:
Use linear search for unsorted data. Use binary/exponential search for sorted data.