Sorting & Searching Programs
C++ n log n vs n². Binary search needs sorted input.
13 programs · open one, then the next
Start with Bubble Sort- 01Bubble SortBeginnerBubble Sort Algorithm in C++ (Complete Implementation).Open example →cpp#include <iostream> using namespace std; void bubbleSort(int arr[], int n) {
- 02Insertion SortBeginnerInsertion Sort Algorithm in C++ (Complete Implementation).Open example →cpp#include <iostream> using namespace std; void insertionSort(int arr[], int n) {
- 03Selection SortBeginnerSelection Sort Algorithm in C++ (Complete Implementation).Open example →cpp#include <iostream> using namespace std; void selectionSort(int arr[], int n) {
- 04Merge SortIntermediateMerge Sort Algorithm in C++ (Complete Implementation).Open example →cpp#include <iostream> using namespace std; void merge(int arr[], int left, int mid, int right) {
- 05Quick SortIntermediateQuick Sort Algorithm in C++ (Complete Implementation).Open example →cpp#include <iostream> using namespace std; int partition(int arr[], int low, int high) {
- 06Heap SortIntermediateHeap Sort Algorithm in C++ (Complete Implementation).Open example →cpp#include <iostream> using namespace std; void heapify(int arr[], int n, int i) {
- 07Radix SortAdvancedRadix Sort Algorithm in C++ (Complete Implementation).Open example →cpp#include <iostream> #include <algorithm> using namespace std;
- 08Counting SortIntermediateCounting Sort Algorithm in C++ (Complete Implementation).Open example →cpp#include <iostream> #include <algorithm> using namespace std;
- 09Linear SearchBeginnerLinear Search Algorithm in C++ (Complete Implementation).Open example →cpp#include <iostream> using namespace std; int linearSearch(int arr[], int n, int key) {
- 10Binary Search (Iterative)BeginnerBinary Search Algorithm in C++ (Iterative Implementation).Open example →cpp#include <iostream> using namespace std; int binarySearch(int arr[], int n, int key) {
- 11Binary Search (Recursive)BeginnerBinary Search Algorithm in C++ (Recursive Implementation).Open example →cpp#include <iostream> using namespace std; int binarySearchRecursive(int arr[], int left, int right, int key) {
- 12Jump SearchIntermediateJump Search Algorithm in C++ (Complete Implementation).Open example →cpp#include <iostream> #include <cmath> using namespace std;
- 13Interpolation SearchIntermediateInterpolation Search Algorithm in C++ (Complete Implementation).Open example →cpp#include <iostream> using namespace std; int interpolationSearch(int arr[], int n, int key) {