Comprehensive Data Structures and Algorithms in C

1. Binary Search

Binary Search Using Recursion

#include <stdio.h>
int binser(int [], int low, int high, int key); // declaration
int main() {
    int n;
    printf("Enter array size: ");
    scanf("%d", &n);
    int arr[n];
    printf("Enter array in sorted order:\n");
    for(int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }
    int key;
    printf("Enter element to search: ");
    scanf("%d", &key);
    int found = binser(arr, 0, n - 1, key);
    if(found == -1) {
Read More