How do I find the probability of some elements being together inside a randomly arranged set? If I have a total of $n$ balls made of $k$ red balls and $(n-k)$ green balls and I arrange them all randomly in a line, how can I calculate the probability $x$ of a group of $y$ red balls being together?

If $k=y$, the solution would be $x=\frac{k!}{n!}$, but I'm striving to find how to deal with cases where $k&gt;y$.
Not an answer in closed form, but it might be useful. I am preassuming that your conditions are also met if there are more than $y$ red balls together.

Let $E_{n,k}$ denote the event that by arranging $k$ red balls and
$n-k$ green balls there will be a consecutive row of at least $y$
red balls. 

Let $R+1$ denote the spot of the first green ball. 

Evidently
$r\geq y$ implies that $P\left(E_{n,k}\mid R=r\right)=1$ and $r&lt;y$
implies $P\left(E_{n,k}\mid R=r\right)=P\left(E_{n-r-1,k-r}\right)$.

Next to that we have $P\left(R=r\right)=\frac{k}{n}\frac{k-1}{n-1}\cdots\frac{k-r+1}{n-r+1}\frac{n-k}{n-r}$
for $r=0,1,\dots,k$. 

There is a recursive relation: $$P\left(E_{n,k}\right)=P\left(R\geq y\right)+\sum_{r=0}^{y-1}P\left(E_{n-r-1,k-r}\right)P\left(R=r\right)$$

Btw, there is some resemblance with this question that deals with "with replacement".
Note: Going by what I believe is the intent of the question, I have made 2 assumptions:

(a) There are at least 2 green balls

(b) k &lt; 2y


Withdraw y red balls and cushion them on each end with a green ball.

Balls remaining in the original group are (k-y) red and (n-k-2) green       totalling (n-y-2) with the red placed in the group in **${n-y-2}\choose{k-y}$ ways. 

You have a sequence G - y reds - G treated as a block to be placed among the     gaps between the (n-y-2)  balls including ends i.e. in (n-y-1) available spots.
Pr = (n-y-1)*${n-y-2}\choose{k-y}$/${n}\choose{k}$