proof of complexity (let all values be 1…𝑛):
𝑦 is an ancestor of 𝑥 iff 𝑦 is the lowest among all values in the range [min(𝑥,𝑦),max(𝑥,𝑦)]. This is with probability 1|𝑦−𝑥+1|. Summing this over all 𝑦 for a fixed 𝑥 means the expected number of ancestors is just 2(12+13+14+15…1𝑛), which is 2log𝑛+𝒪(1)