searches.simple_binary_search¶

Pure Python implementation of a binary search algorithm.

For doctests run following command: python3 -m doctest -v simple_binary_search.py

For manual testing run: python3 simple_binary_search.py

Attributes¶

user_input

Functions¶

binary_search(→ bool)

Module Contents¶

searches.simple_binary_search.binary_search(a_list: list[int], item: int) → bool¶
>>> test_list = [0, 1, 2, 8, 13, 17, 19, 32, 42]
>>> binary_search(test_list, 3)
False
>>> binary_search(test_list, 13)
True
>>> binary_search([4, 4, 5, 6, 7], 4)
True
>>> binary_search([4, 4, 5, 6, 7], -10)
False
>>> binary_search([-18, 2], -18)
True
>>> binary_search([5], 5)
True
>>> binary_search(['a', 'c', 'd'], 'c')
True
>>> binary_search(['a', 'c', 'd'], 'f')
False
>>> binary_search([], 1)
False
>>> binary_search([-.1, .1 , .8], .1)
True
>>> binary_search(range(-5000, 5000, 10), 80)
True
>>> binary_search(range(-5000, 5000, 10), 1255)
False
>>> binary_search(range(0, 10000, 5), 2)
False
searches.simple_binary_search.user_input¶

thealgorithms-python

Navigation

index.md

  • Contributing guidelines
  • Getting Started
  • Community Channels
  • List of Algorithms
  • MIT License
  • API Reference
    • maths
    • other
    • sorts
    • graphs
    • hashes
    • matrix
    • ciphers
    • geodesy
    • physics
    • quantum
    • strings
    • fractals
    • geometry
    • graphics
    • knapsack
    • searches
    • financial
    • blockchain
    • scheduling
    • conversions
    • electronics
    • fuzzy_logic
    • backtracking
    • audio_filters
    • file_transfer
    • project_euler
    • greedy_methods
    • linear_algebra
    • neural_network
    • boolean_algebra
    • computer_vision
    • data_structures
    • networking_flow
    • web_programming
    • bit_manipulation
    • data_compression
    • machine_learning
    • cellular_automata
    • genetic_algorithm
    • divide_and_conquer
    • linear_programming
    • dynamic_programming
    • digital_image_processing

Related Topics

  • Documentation overview
    • API Reference
      • searches
        • Previous: searches.sentinel_linear_search
        • Next: searches.simulated_annealing
©2014, TheAlgorithms. | Powered by Sphinx 8.2.3 & Alabaster 1.0.0 | Page source