Professional Documents
Culture Documents
F 7
F 7
// Copy each character from the original strings to the result array
int index = 0;
5. Binary Search
if (array[mid] == target) {
return mid; // Target found
} else if (array[mid] < target) {
left = mid + 1; // Search in the right half
} else {
right = mid - 1; // Search in the left half
}
}
if (result != -1) {
System.out.println("Element found at index " + result);
} else {
System.out.println("Element not found");
}
}
}