# What is the average expectation value of two specific objects in a queue?

I need some hand to solve this problem.

Suppose a queue can be filled by three type objects (M, F and A). Depending on the number of each objects the line length can be different.

We are looking after the average expectation distance of nearest M and F in any line with given number of $\textit{M,F,A}$.

So the way I solve is: We need to compute the probability with respect to each possible short distance. As a toy problem we have $n_m = 1$ $n_f=2$ and $n_a=1$. Therefore we have different sets for the shortest distance $\{1,2,...\}$, lets call them Gaps.

The probability of gaps depends on number of $n_a$ and are equal to :

P(gap 1) $\rightarrow$ $\frac{n_m}{N}$ * $\frac{n_f}{3}*2$

P(gap 2) $\rightarrow$ $\frac{1}{4}$ * $\frac{1}{3} * \frac{2}{2}*2$

...

P(gap n) $\rightarrow$ $\frac{n_m}{N}$ * $\frac{n_a}{N-1}$ * $\frac{n_a-1}{N-2}$ * ... *$\frac{n_y}{N-(n_a+1)}*2$

and the average expectation: ...

Here is the simulation code in R:

# -----  simulation
rm(list = ls())

nx = 1 # Nm
ny = 2 # Nf
n.alpha = 1 #Na
N = nx+ny+n.alpha

pool.mat = matrix(data=0,nrow = 3000, ncol = N)
itr = 3000
dis.vec = rep(0,itr)
for (cnt in 1:itr)
{
pool = rep(0, N)
xz = sample(c(1:N),nx)
yz = sample(setdiff(c(1:N),xz),ny)

pool[xz] = rep(1, nx)
pool[yz] = rep(2, ny)
pool.mat[cnt,] = pool #check all combinations!
dis.vec[cnt] = min(abs(yz - xz)) #calculate the minimum
}
mean(dis.vec) #average!


So, the value of simulations doesn't really reflect our theoretic solution and the question is how can I derive the right formula.

• It is difficult to understand what is being asked here. My guess is that you are considering uniform random permutations of an array $(x_i)$ of $n_f$ copies of $F$, $n_m$ copies of $M$, and $n_a$ copies of $A$; your random variable $Y$ is the shortest distance between $M$ and $F$ (i.e, $\min\{|i-j|: x_i=M, x_j=F\}$); and you want to compute the expectation of $Y$. But your "toy problem" is confusing because the shortest distance can only equal $1$ or $2$, but the probabilities you assign do not sum to unity! In what respect(s) is my guess incorrect then? – whuber Nov 23 '11 at 21:39
• yes ! you are describing the problem in a very true statistical language ! I just made the toy problem to make clear, but seems it didn't help out ! – user4581 Nov 23 '11 at 23:14
• But what is your question now? Are you asking why your simulation does not agree with your calculation? The calculation is not correct, that's why. In the toy problem P(gap 1) = 5/6 and P(gap 2) = 1/6. The expected gap is 7/6. – whuber Nov 23 '11 at 23:28
• of course simulation is correct :D , the question is how can I derive the right formula ! – user4581 Nov 23 '11 at 23:48
• can we solve the problem, if we fix one type of objects ?! sey we know x is always is position A, and now, whas the average expectation distance of Y and x ?! min{|A|-i}:A=postion(x), i = F} ?? – user4581 Nov 30 '11 at 17:30