<aside> ⚡ Big-O notation describes the upper bound of an algorithm's runtime as the input size grows
</aside>
int linear_search(int a[], int n, int X) {
for (int i = 0; i < n; i++) {
if (a[i] == X) return i;
}
return -1;
}
void matrix_multiply(double a[N][N], double b[N][N], double c[N][N]) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
for (int k = 0; k < N; k++) {
c[i][j] += a[i][k] * b[k][j];
}
}
}
}
void insertion_sort(int a[], int n) {
for (int i = 0; i < n; i++) {
for (int j = i; j > 0 && a[j] < a[j-1]; j--) {
int temp = a[j];
a[j] = a[j-1];
a[j-1] = temp;
}
}
}
int factorial(int n) {
if (n <= 1) return 1;
return n * factorial(n - 1);
}
bool binary_search(int a[], int first, int last, int key) {
if (first > last) return false;
int mid = (first + last) / 2;
if (a[mid] == key) return true;
else if (key < a[mid]) return binary_search(a, first, mid-1, key);
else return binary_search(a, mid+1, last, key);
}
void quicksort(int a[], int begin, int end) {
if (begin < end) {
int pivotIndex = sortAndShuffle(a, begin, end);
quicksort(a, begin, pivotIndex - 1);
quicksort(a, pivotIndex + 1, end);
}
}
int sortAndShuffle(int a[], int begin, int end) {
int pivotValue = a[begin];
int current = begin;
for (int i = begin + 1; i <= end; i++) {
if (a[i] <= pivotValue) {
current++;
int temp = a[current];
a[current] = a[i];
a[i] = temp;
}
}
int temp = a[begin];
a[begin] = a[current];
a[current] = temp;
return current;
}