Companies Home Search Profile

Interview Prep: Binary Search

Focused View

Edaqa Mortoray

26:02

99 View
  • 1. Introduction.mp4
    00:50
  • 2. Algorithm Explanation.mp4
    04:28
  • 3. Algorithm Complexity.mp4
    02:58
  • 4. Lower and Upper Bound.mp4
    05:00
  • 5. Binary Search Code.mp4
    04:32
  • 6. Lower and Upper Bound Code.mp4
    05:42
  • 7. Alternate Binary Search Code.mp4
    02:32
  • More details


    Description

    A quick refresher of this common programming algorithm. Perfect for interview preparation.

    In this class, I look at the binary search algorithm. I walk through some samples and provide the basic complexity analysis. In addition to binary search, I explain lower and upper bound searching. You’ll learn what they are and their purpose.

    Project

    I want you to write a binary search function. Pick a language and write a function that takes an array of values, and an item to look for. The function returns an optional value, the index of where the item is found, or nothing if it wasn’t found. If you’re unfamiliar with optional values, return a `-1` instead, should the value not be found.

    In the example Python implementation, the signature looks like this:

    ```py
    def binary_search( value : ComparableT, items : Sequence[ComparableT] )
    -> Optional[int]:
    ```

    You should assume the array is sorted.

    Upper and Lower Bound

    For extra credits, write the upper and lower bound functions.

    `lower_bound` returns the first index where the item in the list is not less than the input value.

    `upper_bound` returns the first index where the item in the list is greater than the input value.

    For all the algorithms, I provide a walkthrough of sample code. The code is available for you to review.

    Soure Code: https://github.com/mortoray/interview.codes/tree/master/binary-search

    User Reviews
    Rating
    0
    0
    0
    0
    0
    average 0
    Total votes0
    Focused display
    Edaqa Mortoray
    Edaqa Mortoray
    Instructor's Courses
    Hi, I'm Edaqa, a programmer, writer and chef. For over 20 years, I've been following a diverse and exciting career path. My journey traces through several countries, filled with great people and culture. I've dedicated my time to numerous startups, and an abundance of side projects. There's so much I'd like to share with all with you -- from programming to cooking, to the unusual creative endeavours. I want my classes to give you the confidence you need to succeed, and the curiosity required to make the most of life. Join me in my continuing adventures.
    Learn Web Design & Development with SitePoint tutorials, courses and books - HTML, CSS, JavaScript, PHP, Responsive Web Design.
    • language english
    • Training sessions 7
    • duration 26:02
    • Release Date 2023/09/25