allalgorithms-python

Binary Search

In computer science, binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array

Install

pip install allalgorithms

Usage

from allalgorithms.searches import binary_search

arr = [-2, 1, 2, 7, 10, 77]

print(binary_search(arr, 7))
# -> 3

print(binary_search(arr, 3))
# -> None

API

binary_search(array, query)

Return array index if its found, otherwise returns None

Params:
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy