We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5246f63 commit d3b112fCopy full SHA for d3b112f
src/main/java/com/thealgorithms/searches/MetaBinarySearch.java
@@ -0,0 +1,28 @@
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
+}
0 commit comments