




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





Data Structures and Algorithms LECTURE 06: SEARCHING ALGORITHMS
Linear Search int LinearSearch(int arr[], int x) { int n = arr.length; for (int i = 0; i < n; i++) { if (arr[i] == x) return i; } return -1; }
Binary Search (Iterative) int binarySearch(int arr[], int key, int start, int end) { while (end >= start) { int mid = (start + end) / 2; if (arr[mid] < key) start = mid + 1; else if (arr[mid] > key) end = mid - 1; else return mid; } return KEY_NOT_FOUND; }
Searching algorithms Binary Search, Linear Search Summary