Datasets:
ArXiv:
License:
Stack-Repo / data /train /akash-coded /FSD_Java /Lesson-5 /Exponential Search /Assisted Practice Problem /ExponentialSearch.java
Download data/train/akash-coded/FSD_Java/Lesson-5/Exponential Search/Assisted Practice Problem/ExponentialSearch.java from RepoFusion/Stack-Repo: direct link, hf CLI and curl.
- Browser
- Download file 809 Bytes
-
https://huggingface.co/datasets/RepoFusion/Stack-Repo/resolve/bbc90aef76314892f2d54f85da32b81503fb7eb3/data/train/akash-coded/FSD_Java/Lesson-5/Exponential%20Search/Assisted%20Practice%20Problem/ExponentialSearch.java
- Command line
-
hf download 'hf://datasets/RepoFusion/Stack-Repo@bbc90aef76314892f2d54f85da32b81503fb7eb3/data/train/akash-coded/FSD_Java/Lesson-5/Exponential Search/Assisted Practice Problem/ExponentialSearch.java'
-
curl -L -o ExponentialSearch.java https://huggingface.co/datasets/RepoFusion/Stack-Repo/resolve/bbc90aef76314892f2d54f85da32b81503fb7eb3/data/train/akash-coded/FSD_Java/Lesson-5/Exponential%20Search/Assisted%20Practice%20Problem/ExponentialSearch.java
809 Bytes
| import java.util.Arrays; | |
| public class ExponentialSearch { | |
| public static void main(String[] args) { | |
| int[] arr = { 6, 12, 18, 24, 32 }; | |
| int length = arr.length; | |
| int value = 18; | |
| int outcome = exponentialSearch(arr, length, value); | |
| if (outcome < 0) { | |
| System.out.println("Element is not present in the array"); | |
| } else { | |
| System.out.println("Element is present in the array at index: " + outcome); | |
| } | |
| } | |
| public static int exponentialSearch(int[] arr, int length, int value) { | |
| if (arr[0] == value) { | |
| return 0; | |
| } | |
| int i = 1; | |
| while (i < length && arr[i] <= value) { | |
| i = i * 2; | |
| } | |
| return Arrays.binarySearch(arr, i / 2, Math.min(i, length), value); | |
| } | |
| } | |