Probability
Algorithm
Number Theory
Mathematics
Computational Methods

Algorithm for calculating probabilities of a number being drawn opening a book

Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms

Understanding the probability of a number being chosen when you open a book is an intriguing concept involving both randomness and structured probability analysis. This can be approached mathematically by creating relevant algorithms and can also be seen through the lens of probability distribution.

Understanding the Problem

When you open a book to a random page, various factors influence the number/page selection:

  1. Uniform Distribution: If we assume each page has an equal probability of being picked.
  2. Book Bias: Physical properties such as the binding might make certain sections more likely to fall open.
  3. Human Bias: People have tendencies or preferences for certain sections or numerical ranges.

We'll focus on calculating the probabilities assuming a uniform distribution, adding complexity through weight factors, and finally considering real-world imperfections like book bias.

Assumptions

  1. The number of pages, nn, is known.
  2. Each page has an equal probability of being chosen.
  3. We'll explore both theoretical (ideal) and practical (real-world) scenarios.

Theoretical Model: Uniform Distribution

In a perfect setting, each page number from 1 to nn has an equal chance of being selected. Under uniform distribution:

P(selecting page i)=1nP(\text{selecting page } i) = \frac{1}{n}

This simplistic model presumes no additional human or physical biases.

Example:

For a book with 100 pages (n=100n = 100), the probability of opening to page 42 is:

P(page 42)=1100=0.01P(\text{page } 42) = \frac{1}{100} = 0.01

Introducing Weighted Probabilities

Books might have sections with different page quality or people might prefer opening pages with certain content (e.g., illustrations, chapters).

Weight Function

We define a weight function w(i)w(i) which adjusts the probability for each page ii. The total probability is normalized to ensure it sums to 1.

P(selecting page i)=w(i)∑j=1nw(j)P(\text{selecting page } i) = \frac{w(i)}{\sum_{j=1}^{n} w(j)}

Example with Bias:

Consider a book of 5 pages where the central page (page 3) has double the probability of being opened compared to others. w(i)w(i) for pages 1, 2, 4, 5 is 1, and for page 3 is 2.

• Total Weight W=1+1+2+1+1=6W = 1 + 1 + 2 + 1 + 1 = 6 • P(page 3)=26=0.333P(\text{page } 3) = \frac{2}{6} = 0.333 • P(page 1)=16=0.167P(\text{page } 1) = \frac{1}{6} = 0.167

Key Points Table

Pagew(i)w(i)ProbabilityNotes
110.167Standard page
210.167Standard page
320.333Twice as likely due to weight
410.167Standard page
510.167Standard page

Real-World Considerations

Physical Bias

The physical composition of the book might cause certain pages to fall open more easily: • Curvature of the spine causing bias toward middle pages. • Heavily used sections (indexes, prefaces) might flop open easily.

Incorporation of Physical Bias

A refined weight function might consider physical biases, such as centering weights for middle pages or adding higher weights for frequently accessed pages. This results in a more accurate representation of real-world scenarios.

Example:

If the middle of the book (page 50) opens more readily:

• Assign a higher w(i)w(i) for pages near the center. • Recalculate total probability.

Conclusion and Future Work

Through simple models like uniform distribution to advanced weighted functions considering both bias and real-world behavior, calculating probabilities for book-opening scenarios can be effectively modeled. This can be extended by employing stochastic models or machine learning to dynamically adjust weights based on more comprehensive datasets.

Further studies might explore psychological influences, machine learning prediction models, or how different types of books (e.g., novels vs. textbooks) might exhibit varying probabilistic scenarios.


Course
Intermediate
27 lessons
15 hours
DSA Fundamentals

Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.

View the course
Basis Lab
There is a whole course on this

Basis Lab has written “Counting Without Listing”, a course that teaches this from the ground up rather than answering the single question. It is a separate product from the same team and the course is free to read.

Read the course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms