Set 4 - Search

private static int method1(int[] arr, int k) {
        int index = -1;

        for(int i=0; i<arr.length; i++) {
            if (arr[i] == k) {
                index = i;
                break;
            }
        }
        return index;
    }
// BEST CASE TIME COMPLEXITY O(1)
// AVERAGE CASE TIME COMPLEXITY O(N)
// WORST-CASE TIME COMPLEXITY O(N)
// SPACE COMPLEXITY O(1)

Program for Binary Search

Binary search is one of the searching techniques applied when the input is sorted

Method 1: Iterative Method

Method 2: Recursive Method

Method 3: Inbuild Method

Using Arrays binary search method

Method 4: Binary Search in Collection List

Using Binary Search for List

Last updated