HarshCasper / NeoAlgo

Bringing all Data Structures and Algorithms under one Roof âš¡
MIT License
875 stars 1.05k forks source link

binary search without using length function (built-in) in java under GSSOC'22 #7585

Closed Akshitajain1906 closed 1 year ago

Akshitajain1906 commented 2 years ago

🚀 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; }

infinite array

Akshitajain1906 commented 2 years ago

please assign me this issue @HarshCasper /assign

Akshitajain1906 commented 2 years ago

/assign

github-actions[bot] commented 2 years ago

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!

Akshitajain1906 commented 2 years ago

/assign

Akshitajain1906 commented 2 years ago

/assign