Algorithms: Binary Search

HackerRank · 1M views · 2016 · 6:22

Open on YouTube

Algorithms & data structuresEducation & learningtutorial

Why Stack Overflow recommends it

Stack Overflow users link it when explaining binary search and why its running time is logarithmic.

Recommended by 2 people across 2 different months, 2018 to 2021.

What it is

A short HackerRank tutorial that introduces the binary search algorithm, part of the Cracking the Coding Interview series with Gayle Laakmann McDowell. It walks through how repeatedly halving a sorted array finds a target quickly.

What people said

Recommends Omri Attiya · 2019-03 · Stack Overflow · on “How could I add a binary search method using user input in a sorted array”

I'm not sure what you asked but it seems like you are looking for an explanation about the binary search algorithm. In that case I can recommend you to watch this [this video] and for your understanding how it works use this [LINK]

Recommends ricardoramos · 2020-11 · Stack Overflow · on “Why is the complexity of the binary search Log in base 2?”

Considering the answers, comments and the following video: StackOverflow response 1 [LINK] StackOverflow response 2 [LINK] Binary Search Video [this video] @Mo B. comment: The question is not: how many cuts are necessary to get 16 slices. But rather: how many cuts are necessary to get a slice of size 1? And that's 4. In other words, like in the algorithm, you cut in half and throw away one of the halves at each step. How often can you do that with an array of size 16? @Yves Daoust comment: The logarithm of a number is roughly the number of times you can halve it until you reach 1. My conclusions are: The logarithm of a array of size n is approximately the number of times we can divide it in half

Recommends ricardoramos · 2020-11 · Stack Overflow · on “Why is the complexity of the binary search Log in base 2?”

@MoB. thank you very much for all your help! Your comment helped me to understand better. In addition, I also used the following answer: [LINK] and also watched the video [this video] from 2:30 onwards.

Cites Stevenjac · 2018-08 · Stack Overflow · on “Binary Search Time Complexity: Why does base 2 does not matter in log base 2 of n?”

Binary search time is often described as log base 2 of n. How come the base 2 is often discarded like in this video? [this video]

Cites Tom Hamming · 2021-06 · Stack Overflow · on “How do you read the %in% operator in plain English?”

I think your disconnect is understanding how to apply "in" to a vector. You wrote that you want to read it as "Look for 11 and 12 in the month column." You can indeed think of it that way. Your example was: nov_dec <- filter(flights, month %in% c(11, 12)) And that could be expressed in plain English as: Give me all the flights where one of the values in c(11, 12) is in the month column But we could also say that 11 and 12 are "in" the vector c(11, 12) . That's what the left-to-right reading would be: Give me all the flights whose month is in the vector c(11, 12) . Or, expressed slightly differently and more verbosely: Give me all the flights whose month is equal to one of the values in the v