Skip to content

Commit 1c72d8d

Browse files
authored
Create stick break
1 parent 4579659 commit 1c72d8d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

interview_query/stick break

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
If you break a stick uniformly at two points, creating three pieces, what’s the probability that a triangle can be formed from the three pieces?
2+
3+
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4+
5+
Recall the triangle inequality, which says that the combined length of any two sides of a triangle has to be less than or equal to the third side. So in our stick case, we’ll be able to form a triangle if none of the three pieces is ≥ 1⁄2 the total length of the stick.
6+
7+
So how to figure out the probability that none of the three pieces is greater than 1⁄2?
8+
9+
The question says that the cuts will be made uniformly, that is, using a uniform distribution.
10+
11+
So if our stick is of length 1, using a uniform distribution means that there is a 1⁄2 probability that both cuts will be made on the same side of the mid-point. This precludes half of the possible cuts from being able to form a triangle. So now P(triangle) is at most 1⁄2. But we’re not done yet!
12+
13+
If the two cuts happen on different sides of the middle point, this still doesn’t guarantee a triangle.
14+
15+
Assume the cuts are labeled a and b, and that a and b are on different sides of the middle point, M. This will happen half of the time.
16+
17+
———-a——-——M———-b——-——
18+
19+
To be able to make a triangle, the distance from a to b can’t be more than half of the stick. This is only possible if a or b is closer to M than the end of the stick. This will happen half the time that the breaks are on either side of M (already only half of the total probability).
20+
21+
So the total P(triangle) is 1⁄4.
22+
23+
In summary: half the time both breaks are on the same side, so no triangle is formed. For the other half of the time, when the breaks are on either side of the middle, half the time the middle stick is larger than half the total, so no triangle is formed.

0 commit comments

Comments
 (0)