How to search binary in a sorted array?



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

Post New Answer

More Data Structures Interview Questions

Which is the parent class of enumset class?

1 Answers  


What is binary search in data structure?

1 Answers  


Can hashset contain null?

1 Answers  


What is a multidimensional array?

1 Answers  


What is a stable sort?

1 Answers  


What is a weighted graph?

1 Answers  


Which data structures are applied when dealing with a recursive function?

1 Answers  


What is the types of data structure?

1 Answers  


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.

1 Answers  


Two linked lists are given, find out the sum of them without altering the linked list?

1 Answers   Expedia,


Run time memory allocation is known as in data structure?

1 Answers  


Categories