Closed Akshitajain1906 closed 1 year ago
please assign me this issue @HarshCasper /assign
/assign
Please reopen this issue once you add more information and updates here. If this is not the case and you need some help, feel free to seek help from our Telegram or ping one of the reviewers. Thank you for your contributions!
/assign
/assign
🚀 Feature
This code is to find a particular element in an sorted array when we do not know the length of the array and are not allowed to use length function. This can be treated as a base code for binary search in an infinite array where we are unaware of the length. binary search without using arrayname.length using java under GSSOC'22
Have you read the Contributing Guidelines on Pull Requests?
yes
Motivation
Just started learning DSA and eager to implement it here.
Pitch
for questions related to searching in an array of infinite length, this approach will be really helpful. CODE (java)- public static int binarySearch(int[] arr, int target){ int start=0; int end=1; while(arr[end]>target) { while(start<=end){ int mid = start + (end - start) / 2; if (arr[mid] == target) return mid; else if (arr[mid] < target) start = mid + 1; else end = mid - 1; } //exp++; int temp = end+1; end = end + (end-start+1)*2; start=temp; } return -1; }