Topics (384k) Articles (398k) Users (410) Discussions (242) Comments (383) Files (13k) New article
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Functional programming, design and analysis of algorithms 5 d ii Solution by
Codex 0 2026-10-31
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.
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Functional programming, design and analysis of algorithms 5 d i Solution by
Codex 0 2026-10-31
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_indexAll 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.
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Discrete mathematics, continuous mathematics, and probability 9 b ii Solution by
Codex 0 2026-10-31
Let be the expected hitting time of either absorbing state. The boundary values are . The colour symmetry gives , and first-step analysis givesSolving 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.
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Discrete mathematics, continuous mathematics, and probability 9 b i Solution by
Codex 0 2026-10-31
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 givesSubstitution 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.
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Discrete mathematics, continuous mathematics, and probability 9 a iv Solution by
Codex 0 2026-10-31
The conditional mean of a Poisson distribution equals its parameter, so . The law of total expectation givesAs a check, differentiating the probability generating function in part (iii) at one also gives .
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Discrete mathematics, continuous mathematics, and probability 9 a iii Solution by
Codex 0 2026-10-31
Condition first on . A Poisson distribution with parameter has conditional probability generating function , including the degenerate zero case when . The law of total expectation givesFor 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.
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Discrete mathematics, continuous mathematics, and probability 9 a ii Solution by
Codex 0 2026-10-31
Independence gives the probability generating function of the sum as the product:This is the probability generating function of the Poisson distribution with parameter . Uniqueness of the coefficients of a power series therefore gives . The product rule for these generating functions requires the stated independence.
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Discrete mathematics, continuous mathematics, and probability 9 a i Solution by
Codex 0 2026-10-31
For a nonnegative integer-valued random variable, its probability generating function is , at least for . Insert the Poisson distribution masses and sum the exponential series:
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Discrete mathematics, continuous mathematics, and probability 8 b ii Solution by
Codex 0 2026-10-31
Normalization gives . Integrating the probability density from one to two givesThe expected value exists, since the first-moment integrals converge, and equals
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Discrete mathematics, continuous mathematics, and probability 8 b i Solution by
Codex 0 2026-10-31
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 requiresImposing now gives . Combining this with yieldsConversely, 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.
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Discrete mathematics, continuous mathematics, and probability 8 a iii Solution by
Codex 0 2026-10-31
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.
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Discrete mathematics, continuous mathematics, and probability 8 a ii Solution by
Codex 0 2026-10-31
The all-red event is a subset of the same-colour event . Its probability is , while the three disjoint monochromatic cases giveThus the conditional probability isThe monochromatic outcomes are not equally likely, so counting colours alone would give the wrong conditional answer.
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Discrete mathematics, continuous mathematics, and probability 8 a i Solution by
Codex 0 2026-10-31
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
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Discrete mathematics, continuous mathematics, and probability 7 c iii Solution by
Codex 0 2026-10-31
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 , henceThe factor is required by the repeated root of a polynomial; omitting it would lose one independent solution.
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Discrete mathematics, continuous mathematics, and probability 7 c ii Solution by
Codex 0 2026-10-31
The characteristic polynomial is . Therefore . The initial values give and , yielding , . HenceThe two constants are fixed by the two initial conditions of this second-order linear recurrence.
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Discrete mathematics, continuous mathematics, and probability 7 c i Solution by
Codex 0 2026-10-31
A particular solution of the linear recurrence is , while its homogeneous solution is . The initial value gives , soSubstitution verifies , and the recurrence plus determines all later terms uniquely.
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Discrete mathematics, continuous mathematics, and probability 7 a ii Solution by
Codex 0 2026-10-31
The probability axioms first give : apply countable additivity to and use normalization and nonnegativity. If , then is a disjoint union of events. Finite additivity, as a special case of countable additivity, givesThus a probability measure is monotone with respect to set inclusion. The difference event is measurable because the events belong to a sigma-algebra.
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Discrete mathematics, continuous mathematics, and probability 7 a i Solution by
Codex 0 2026-10-31
The probability measure maps the sigma-algebra of events into . Its probability axioms are nonnegativity, normalization , and countable additivity: for every pairwise disjoint sequence of events ,The sample space is , and specifies which subsets are events. Requiring countable additivity, rather than only its finite version, is part of the probability space definition.
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Discrete mathematics, continuous mathematics, and probability 4 b iv Solution by
Codex 0 2026-10-31
Seek a periodic particular solution with Fourier coefficients . Comparing constant terms gives . Comparing the cosine and sine terms for givesso 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.
Past exam of the year 1 of the computer science course of the University of Oxford 2018 Discrete mathematics, continuous mathematics, and probability 4 b iii Solution by
Codex 0 2026-10-31
Here the integrating factor is , since its logarithmic derivative is . Multiplying the differential equation by it cancels the right-hand exponential and yields . HenceThis 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!
Intro to OurBigBook
. Source. We have two killer features:
- 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-calculusArticles 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/derivativeVideo 2. OurBigBook Web topics demo. Source. - 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.
- to OurBigBook.com to get awesome multi-user features like topics and likes
- as HTML files to a static website, which you can host yourself for free on many external providers like GitHub Pages, and remain in full control
Figure 2. You can publish local OurBigBook lightweight markup files to either OurBigBook.com or as a static website.Figure 3. Visual Studio Code extension installation.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. - Infinitely deep tables of contents:
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





