#include "head.h"

int linear_Search(int *arr, int n, int key) {
    for (int i = 0; i < n; i++)
        if (arr[i] == key) return i;
    return -1;
}

int exponential_Search(int *arr, int n, int key) {
    int a = 1; 
    while (a < n && arr[a - 1] < key) 
        a *= 2;
    
    int low = a / 2;
    int high = (a < n) ? a : n;
    
    while (low <= high) {
        int mid = low + (high - low) / 2;
        if (arr[mid] == key) return mid;
        if (arr[mid] < key) low = mid + 1;
        else high = mid - 1;
    }
    return -1;
}

int binary_Search(int *arr, int n, int key) {
    int low = 0;
    int high = n - 1;
    while (low <= high) {
        int mid = low + (high - low) / 2;
        if (arr[mid] == key) return mid;
        if (arr[mid] < key) low = mid + 1;
        else high = mid - 1;
    }
    return -1;
}
