[computer-go] OT: median of a data stream

2007-08-16 Thread Darren Cook
Apologies for the off-topic post, but I know lots of people here are interested in statistics and algorithms. Calculating the mean of a stream of numbers [1] is easy: just keep track of the sum and the count, and divide at the end. But what about the median? I think I always need to buffer at

Re: [computer-go] OT: median of a data stream

2007-08-16 Thread John Tromp
On 8/16/07, Darren Cook [EMAIL PROTECTED] wrote: Apologies for the off-topic post, but I know lots of people here are interested in statistics and algorithms. Calculating the mean of a stream of numbers [1] is easy: just keep track of the sum and the count, and divide at the end. But what

Re: [computer-go] OT: median of a data stream

2007-08-16 Thread Erik van der Werf
On 8/16/07, Darren Cook [EMAIL PROTECTED] wrote: Calculating the mean of a stream of numbers [1] is easy: just keep track of the sum and the count, and divide at the end. But what about the median? I think I always need to buffer at least half the numbers A counter for each unique value

Re: [computer-go] OT: median of a data stream

2007-08-16 Thread A van Kessel
You can use a binary tree. In each node you store the number of child nodes in the left subtree. (maybe also for the right subtree) If you want to handle duplicates, you could add yet another counter to the nodes. Finding the median is easy. As a bonus, you can also find the value for *any* rank