Find all polynomials 

$f(x) = x^{n} + a_{1}x^{n-1} + \cdots + a_{n}$

with the following properties

(a) all the coefficients $a_{1}, a_{2}, ..., a_{n}$ belong to the set $\{ -1, 1 \}$; and
(b) all the roots of the equation $f(x)=0$ are real.
1. **Identify the polynomial and its properties:**
   We are given a polynomial \( f(x) = x^n + a_1 x^{n-1} + \cdots + a_n \) where the coefficients \( a_1, a_2, \ldots, a_n \) belong to the set \(\{-1, 1\}\). Additionally, all roots of the polynomial are real.

2. **Use Vieta's formulas:**
   By Vieta's formulas, the sum of the roots taken one at a time (with sign) is given by:
   \[
   s_1 + s_2 + \cdots + s_n = -a_1
   \]
   The sum of the products of the roots taken two at a time is:
   \[
   s_1 s_2 + s_1 s_3 + \cdots + s_{n-1} s_n = a_2
   \]
   The product of the roots (with sign) is:
   \[
   (-1)^n s_1 s_2 \cdots s_n = (-1)^n a_n
   \]

3. **Analyze the sum of squares of the roots:**
   The sum of the squares of the roots can be expressed as:
   \[
   \sum_{i=1}^n s_i^2 = (s_1 + s_2 + \cdots + s_n)^2 - 2 \sum_{1 \le i < j \le n} s_i s_j
   \]
   Using Vieta's formulas, this becomes:
   \[
   \sum_{i=1}^n s_i^2 = (-a_1)^2 - 2a_2 = 1 - 2a_2
   \]

4. **Consider the constraints on the sum of squares:**
   Since all roots are real, the sum of the squares of the roots must be non-negative:
   \[
   \sum_{i=1}^n s_i^2 \geq 0
   \]
   Additionally, since \(a_2\) can only be \(-1\) or \(1\), we have:
   \[
   1 - 2a_2 \leq 3
   \]
   This implies:
   \[
   1 - 2a_2 \geq n
   \]

5. **Determine the possible values of \(n\):**
   Combining the inequalities, we get:
   \[
   n \leq 3
   \]
   Therefore, \(n\) can be \(1\), \(2\), or \(3\).

6. **Case analysis for \(n = 1, 2, 3\):**
   - For \(n = 1\):
     \[
     f(x) = x + a_1
     \]
     The root is \(x = -a_1\), which is real. Both \(a_1 = 1\) and \(a_1 = -1\) are valid.

   - For \(n = 2\):
     \[
     f(x) = x^2 + a_1 x + a_2
     \]
     The discriminant must be non-negative for real roots:
     \[
     a_1^2 - 4a_2 \geq 0
     \]
     Substituting \(a_1\) and \(a_2\) from \(\{-1, 1\}\), we find that all combinations satisfy the discriminant condition.

   - For \(n = 3\):
     \[
     f(x) = x^3 + a_1 x^2 + a_2 x + a_3
     \]
     The discriminant condition is more complex, but we can check specific polynomials:
     - \(f(x) = x^3 + x^2 + x + 1\) has no real roots.
     - \(f(x) = x^3 - x^2 + x - 1\) has no real roots.
     - \(f(x) = x^3 + x^2 - x - 1\) has no real roots.
     - \(f(x) = x^3 - x^2 - x + 1\) has no real roots.

   Therefore, for \(n = 3\), no polynomials satisfy the conditions.

The final answer is \( \boxed{ n = 1 } \) or \(n = 2\).