SitePoint
  • Premium
  • Library
  • Community
  • Jobs
  • Blog
LoginStart Free Trial

The home for developers

Track your course progress, manage projects, and find your dream job - all in one place.

Start Your Free Trial

7 Day Free Trial. Cancel Anytime.

SitePoint Premium

  • Access to 700+ courses
  • Publish articles on SitePoint
  • Daily curated jobs
  • Learning Paths
  • Discounts to dev tools
  • Library/
  • Video courses/
  • Interview Prep: Binary Search
Interview Prep: Binary Search

Interview Prep: Binary Search

Refresh your knowledge of this commonly used algorithm


Course details

0∙0 Ratings0 reviews

Published
April 2020
Videos
7
Duration
Happy students
61

Take this course

About the course

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

Course Instructor

Course Outline

Lesson 1: Interview Prep: Binary Search
  • Free
    Introduction
    0:50
  • Locked
    Algorithm Explanation
    4:28
  • Locked
    Algorithm Complexity
    2:58
  • Locked
    Lower and Upper Bound
    5:00
  • Locked
    Binary Search Code
    4:32
  • Locked
    Lower and Upper Bound Code
    5:42
  • Locked
    Alternate Binary Search Code
    2:32

Reviews

0 total

0
0
0
0
0

Course details

0∙0 Ratings0 reviews

Published
April 2020
Videos
7
Duration
Happy students
61

Take this course
SitePoint

Stuff we do

  • Premium
  • Newsletters
  • Learning paths
  • Library
  • Forums

Contact

  • Contact us
  • FAQ
  • Publish your book
  • Write an article
  • Advertise

About

  • Our Story
  • Corporate Memberships
  • Start free trial
  • Login

Connect

  • RSS
  • Facebook
  • Twitter (X)
  • Instagram

Subscribe to our newsletter

Get the freshest news and resources for developers, designers and digital creators in your inbox each week

© 2000 – 2025 SitePoint Pty. Ltd.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Terms of usePrivacy policy