In studying the random walk in one dimension I had a doubt on basic probability. The point is the following: we consider a random walk with $N$ steps consiting of $n_1$ steps to the right and $n_2$ steps to the left. The probability that one step will be to the right is $p$ and the probability one step will be to the left is $q = 1-p$. Also, it is considered each step is independent of the last one.
The book states, however, that the probability of getting any one sequence with $n_1$ steps to the right is simply $p^{n_1}q^{N-n_1}$, that is, multiplying $p$ by itself $n_1$ times.
Why is that? I know from probability that if $A$ and $B$ are independent events then $P(A\cap B) = P(A)P(B)$ and the result would follow.
But I can't see how this relates to the present case. Indeed, $A,B$ as above are events of the same sample space $S$, but on the random walk problem it seems we have two sample spaces:
The sample space $S_1$ of the experiment of watching one step. Then $S_1 = \{-1,1\}$ being $-1$ to the left and $1$ to the right, and we have $P(\{-1\}) = q$ and $P(\{1\}) = p$.
The sample space $S_2$ of the experiment of watching $N$ steps. Then $S_2 = \{(i_1,\dots, i_N) : i_k = -1,1\}$ that is all sequences of steps or to the right or to the left.
How from this could we deduce that the probabilty of any sequence with $n_1$ steps to the right, that is any sequence $(i_1,\dots, i_N)$ with $n_1$ $1$'s appearing is $p^{n_1}q^{N-n_1}$?
The correct way to define the random walk is to consider independent identically distributed random variables $\xi_n$, with $P(\xi_n=+1)=p$ and $P(\xi_n=-1)=1-p$, and then consider the sum $X_n=\xi_1+\dots+\xi_n$ which gives you the position of the random walk started at $0$ at time $n$.
You can think of the sample space as being sequences of $N$ coin-flips of an unfair coin. If it's heads ($\xi_n=+1$) you move right, if it is tails ($\xi_n=-1$) you move left.
The probability that you have a particular sequence of (at least) $n_1$ steps to the right, say the first steps from time $1$ to $n_1$ are to the right, is $P(\xi_1=1,\xi_2=1,\dots,\xi_{n_1}=1)= P(\xi_1=1)P(\xi_2=1)\cdots P(\xi_{n_1}=1)=p^{n_1}$
Similarly, the probability of any particular sequence consisting of at least $n_1$ steps to the right is $p^{n_1}$.