Let f(g;n,m)f(g;n,m) be the chance that the minimum, a(1)a(1), equals gg; that is, the sample consists of gg and an n−1n−1-subset of {g+1,g+2,…,m}{g+1,g+2,…,m}. There are (m−gn−1)(m−gn−1) such subsets out of the (mn)(mn) equally likely subsets, whence
Pr(a(1)=g=f(g;n,m)=(m−gn−1)(mn).
Pr(a(1)=g=f(g;n,m)=(m−gn−1)(mn).
Adding f(k;n,m)f(k;n,m) for all possible values of kk greater than gg yields the survival function
Pr(a(1)>g)=Q(g;n,m)=(m−g)(m−g−1n−1)n(mn).
Pr(a(1)>g)=Q(g;n,m)=(m−g)(m−g−1n−1)n(mn).
Let Gn,mGn,m be the random variable given by the largest gap:
Gn,m=max(a(1),a(2)−a(1),…,a(n)−a(n−1)).
Gn,m=max(a(1),a(2)−a(1),…,a(n)−a(n−1)).
(This responds to the question as originally framed, before it was modified to include a gap between a(n)a(n) and mm.)
We will compute its survival function P(g;n,m)=Pr(Gn,m>g),
P(g;n,m)=Pr(Gn,m>g),
from which the entire distribution of
Gn,mGn,m is readily derived. The method is a dynamic program beginning with
n=1n=1, for which it is obvious that
P(g;1,m)=Pr(G1,m>1)=m−gm, g=0,1,…,m.
P(g;1,m)=Pr(G1,m>1)=m−gm, g=0,1,…,m.(1)
For larger n>1n>1, note that the event Gn,m>gGn,m>g is the disjoint union of the event
a1>g,
a1>g,
for which the very first gap exceeds gg, and the gg separate events
a1=k and Gn−1,m−k>g, k=1,2,…,g
a1=k and Gn−1,m−k>g, k=1,2,…,g
for which the first gap equals kk and a gap greater than gg occurs later in the sample. The Law of Total Probability asserts the probabilities of these events add, whence
P(g;n,m)=Q(g;n,m)+g∑k=1f(k;n,m)P(g;n−1,m−k).
P(g;n,m)=Q(g;n,m)+∑k=1gf(k;n,m)P(g;n−1,m−k).(2)
Fixing gg and laying out a two-way array indexed by i=1,2,…,ni=1,2,…,n and j=1,2,…,mj=1,2,…,m, we may compute P(g;n,m)P(g;n,m) by using (1)(1) to fill in its first row and (2)(2) to fill in each successive row using O(gm)O(gm) operations per row. Consequently the table can be completed in O(gmn)O(gmn) operations and all tables for g=1g=1 through g=m−n+1g=m−n+1 can be constructed in O(m3n)O(m3n) operations.
These graphs show the survival function g→P(g;n,64)g→P(g;n,64) for n=1,2,4,8,16,32,64n=1,2,4,8,16,32,64. As nn increases, the graph moves to the left, corresponding to the decreasing chances of large gaps.
Closed formulas for P(g;n,m)P(g;n,m) can be obtained in many special cases, especially for large nn, but I have not been able to obtain a closed formula that applies to all g,n,mg,n,m. Good approximations are readily available by replacing this problem with the analogous problem for continuous uniform variables.
Finally, the expectation of Gn,mGn,m is obtained by summing its survival function starting at g=0g=0:
E(Gn,m)=m−n+1∑g=0P(g;n,m).
E(Gn,m)=∑g=0m−n+1P(g;n,m).
This contour plot of the expectation shows contours at 2,4,6,…,322,4,6,…,32, graduating from dark to light.