This egg will help you solve the most common computer science algorithm!

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

In reality, an egg will break just from the height of your hands

malemsana_only
Автор

The analogy is fine, but the question proposed is wrong. The question asks the lowest floor you can drop it from, not the highest without breaking. Thus, the answer is always the first 1st floor. Therefore, the question should have been the highest floor you can drop it from without it breaking.

vaasuph
Автор

Cool problem....😊 Sort Algo speed Big O notation...Is this O(log n) or O(n/2) or O(n)

curtisdavis
Автор

Binary search is not the best approach here, because it doesn't give you precise answer without O(log n) eggs to break. But you can solve it using just 2 eggs.

Using an interesting trick called "Square root decomposition"

Lets say we have 100 floor building and 2 eggs. Then we splin ohr array into sections of a size sqrt(n) = 10

First egg we will throw with sqrt(n) jumps starting with 10, and going 20, 30, ..., 100

Let's say egg breaks at floor 50. The the answer is between 40 and 50. Lets take the second agg and throw it with steps 1.

Thus it will take only 2 eggs and sqrt(n) time to find the precise answer

sergokovaltsov
Автор

You just taught people binary search. When I was a lines man trying to find breaks in the telephone lines, I did the exact same thing and taught it to my colleagues, yes I used to work on telephone lines 30 years ago. I'm a C++ developer now.

colinmaharaj
Автор

I didn’t know there was a term for that. I use it in other parts of life.

Fullyautomagic
Автор

It can't cuz you can't drop an egg more than a ft from the ground and it'll break... answer is 1st floor

tonyVotino
Автор

Lmao this is a lame analogy. If it didn’t break at the 25th floor then that means the closest floor where it won’t brake is the 1st floor😂

hklyt