Maintain a residual cumulative-weight target , initially , while discarding whole partitions. Choose pivots by an ordinary median of the current entries, not by their weights:
selectWeighted(S, t):
    if |S| == 1: return the sole record of S
    p = deterministic unweighted median by value in S
    L = records with value < p.value
    R = records with value > p.value
    ell = sum of weights in L
    if t <= ell:
        return selectWeighted(L, t)
    if t <= ell + p.weight:
        return p
    return selectWeighted(R, t - ell - p.weight)

answer = selectWeighted(all records, 1/2)
The invariant is , with the desired answer the first cumulative weight reaching inside the current ordered subset. The first branch uses <=, which is essential: if the target equals the total left mass, the answer is the largest appropriate left-side value, not the pivot. The other branches preserve the residual target by subtracting exactly the mass discarded on the left.
A median of medians routine finds the exact unweighted median in deterministic linear time. Partitioning and summing also take linear time, and each recursive call retains at most entries. Therefore . The algorithm is worst-case linear, not merely expected linear under a random pivot. Exact comparisons to the weight threshold are assumed; floating-point rounding at exactly one half would need explicit treatment.
Keep each weight attached to its value while sorting, then return the first cumulative weight reaching one half:
weightedMedian(A, weights):
    R = records (A[i], weights[i], i), sorted by first component
    cumulative = 0
    for (value, weight, original_index) in R:
        cumulative = cumulative + weight
        if cumulative >= 1/2:
            return original_index
All weights are positive, so the cumulative weights strictly increase. At the returned entry the mass strictly to its left is below one half, while the mass strictly to its right is at most one half. This is the lower weighted median, including the exact equality case: stop at the earlier value whose cumulative mass is exactly one half. Sorting takes and the scan takes , giving time.
Let be the expected hitting time of either absorbing state. The boundary values are . The colour symmetry gives , and first-step analysis gives
Solving gives and . Thus the expected total number of draws from the stated initial condition is seven. The additive one counts the current draw. Finiteness follows from the uniform two-step absorption bound in part (i), so the first-step equations do not hide an assumption of finite expectation.
Let count red balls and let be the probability of eventual absorption at starting from . The birth-death chain moves to with probability and to with probability . Its absorbing states have , . First-step analysis gives
Substitution yields , and . The initial state has one red ball, so the probability that all balls end white is .
Absorption occurs almost surely: from each interior state there is probability at least of absorption within the next two draws. The chance of surviving draws is therefore at most . This also justifies the finite expected times used in part (ii). The process is the absorbing four-ball Ehrenfest chain.
Condition first on . A Poisson distribution with parameter has conditional probability generating function , including the degenerate zero case when . The law of total expectation gives
For the inner argument is in , so this use of the generating function is justified directly. The result is a compound Poisson distribution with a Poisson distribution of unit parameter for each jump, also called a Neyman Type A distribution in this case. It is generally not an ordinary Poisson distribution.
Normalization gives . Integrating the probability density from one to two gives
The expected value exists, since the first-moment integrals converge, and equals
For , write the proposed density as . Since the first factor is positive, nonnegativity for all such requires ; if , values sufficiently close to one make it negative. With , the positive tail is integrable only if . In that case normalization requires
Imposing now gives . Combining this with yields
Conversely, these conditions ensure a nonnegative, integrable function with integral one, so they are sufficient as well as necessary. The endpoint is allowed: the density vanishes at the left-hand boundary limit, not on its whole support.
Let be the indicator random variable that colour appears at least once. Then . For a colour of single-roll probability , independence of rolls gives . By linearity of expectation,
The three indicators are not independent, but linearity of expectation does not require them to be. This is the expected number of observed categories.
The all-red event is a subset of the same-colour event . Its probability is , while the three disjoint monochromatic cases give
Thus the conditional probability is
The monochromatic outcomes are not equally likely, so counting colours alone would give the wrong conditional answer.
The single-roll colour probabilities are , and . There are possible orders of the three distinct colours, and the independent rolls give each order probability . The events are disjoint, so the required probability is
The characteristic polynomial of the homogeneous linear recurrence is , so its repeated-root solutions are . A constant particular solution is one. Thus . The initial conditions give and , hence
The factor is required by the repeated root of a polynomial; omitting it would lose one independent solution.
The characteristic polynomial is . Therefore . The initial values give and , yielding , . Hence
The two constants are fixed by the two initial conditions of this second-order linear recurrence.
A particular solution of the linear recurrence is , while its homogeneous solution is . The initial value gives , so
Substitution verifies , and the recurrence plus determines all later terms uniquely.
Seek a periodic particular solution with Fourier coefficients . Comparing constant terms gives . Comparing the cosine and sine terms for gives
so and . Insert the coefficients from part (a) and add the homogeneous solution:
The differentiated series converges absolutely and uniformly, because its largest coefficient terms are . This justifies the term-by-term first derivative used in substituting into the differential equation. Any two solutions differ by , proving that the displayed family is the general solution. The computation is an instance of Fourier response of a first-order linear differential equation.
Here the integrating factor is , since its logarithmic derivative is . Multiplying the differential equation by it cancels the right-hand exponential and yields . Hence
This formula is actually defined for every real .

Pinned article: Introduction to the OurBigBook Project

Welcome to the OurBigBook Project! Our goal is to create the perfect publishing platform for STEM subjects, and get university-level students to write the best free STEM tutorials ever.
Everyone is welcome to create an account and play with the site: ourbigbook.com/go/register. We belive that students themselves can write amazing tutorials, but teachers are welcome too. You can write about anything you want, it doesn't have to be STEM or even educational. Silly test content is very welcome and you won't be penalized in any way. Just keep it legal!
We have two killer features:
  1. topics: topics group articles by different users with the same title, e.g. here is the topic for the "Fundamental Theorem of Calculus" ourbigbook.com/go/topic/fundamental-theorem-of-calculus
    Articles of different users are sorted by upvote within each article page. This feature is a bit like:
    • a Wikipedia where each user can have their own version of each article
    • a Q&A website like Stack Overflow, where multiple people can give their views on a given topic, and the best ones are sorted by upvote. Except you don't need to wait for someone to ask first, and any topic goes, no matter how narrow or broad
    This feature makes it possible for readers to find better explanations of any topic created by other writers. And it allows writers to create an explanation in a place that readers might actually find it.
    Figure 1.
    Screenshot of the "Derivative" topic page
    . View it live at: ourbigbook.com/go/topic/derivative
  2. local editing: you can store all your personal knowledge base content locally in a plaintext markup format that can be edited locally and published either:
    This way you can be sure that even if OurBigBook.com were to go down one day (which we have no plans to do as it is quite cheap to host!), your content will still be perfectly readable as a static site.
    Figure 5. . You can also edit articles on the Web editor without installing anything locally.
    Video 3.
    Edit locally and publish demo
    . Source. This shows editing OurBigBook Markup and publishing it using the Visual Studio Code extension.
  3. https://raw.githubusercontent.com/ourbigbook/ourbigbook-media/master/feature/x/hilbert-space-arrow.png
  4. Infinitely deep tables of contents:
    Figure 6.
    Dynamic article tree with infinitely deep table of contents
    .
    Descendant pages can also show up as toplevel e.g.: ourbigbook.com/cirosantilli/chordate-subclade
All our software is open source and hosted at: github.com/ourbigbook/ourbigbook
Further documentation can be found at: docs.ourbigbook.com
Feel free to reach our to us for any help or suggestions: docs.ourbigbook.com/#contact