Back to Freecodecamp

Step 6

curriculum/challenges/english/blocks/workshop-binary-search/683ec95f2f8781355556ff7e.md

latest972 B
Original Source

--description--

Now that you've calculated the mid index, you need to actually retrieve the value from the search_list at that index. This value is what you will compare against your value parameter, which is the target you are searching for.

Create a value_at_middle variable and assign it the element from search_list that is located at the mid index.

--hints--

You should create a value_at_middle variable set to search_list[mid].

js
({
    test: () =>
        assert(
            runPython(
                `_Node(_code).find_function("binary_search").find_whiles()[0].find_body().is_equivalent("mid = (low + high) // 2 \\nvalue_at_middle = search_list[mid]")`))
})

--seed--

--seed-contents--

py
def binary_search(search_list, value):
    path_to_target = []
    low = 0
    high = len(search_list) - 1
    
--fcc-editable-region--
    while low <= high:
        mid = (low + high) // 2

        
--fcc-editable-region--