File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
src/main/java/com/thealgorithms/searches Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .thealgorithms .searches ;
2+
3+ public class MetaBinarySearch {
4+
5+ // Implementing Meta Binary Search algorithm
6+ public int metaBinarySearch (int [] sortedArray , int target ) {
7+ if (sortedArray == null || sortedArray .length == 0 ) {
8+ return -1 ; // Array is empty or null
9+ }
10+
11+ int left = 0 ;
12+ int right = sortedArray .length - 1 ;
13+
14+ while (left <= right ) {
15+ int mid = left + (right - left ) / 2 ;
16+
17+ if (sortedArray [mid ] == target ) {
18+ return mid ; // Target found
19+ } else if (sortedArray [mid ] < target ) {
20+ left = mid + 1 ; // Move to the right half
21+ } else {
22+ right = mid - 1 ; // Move to the left half
23+ }
24+ }
25+
26+ return -1 ; // Target not found
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments