How to search binary in a sorted array?
Answer / Ujjwal Kumar
Binary Search is an efficient algorithm for finding a specific element within a sorted array. It repeatedly divides the array in half, and compares the target value with the middle element. Here's a simple implementation in Python:
```python
def binarySearch(arr, target):
low = 0
high = len(arr) - 1
while low <= high:
mid = (low + high) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
low = mid + 1
else:
high = mid - 1
return -1
```
| Is This Answer Correct ? | 0 Yes | 0 No |
Which is the parent class of enumset class?
What is binary search in data structure?
Can hashset contain null?
What is a multidimensional array?
What is a stable sort?
What is a weighted graph?
Which data structures are applied when dealing with a recursive function?
What is the types of data structure?
Write is a binary search tree? Write an algorithm and tell complexity?
1 Answers ITC Indian Tobacco Company,
What are different dynamic memory allocation technique in c.
Two linked lists are given, find out the sum of them without altering the linked list?
Run time memory allocation is known as in data structure?