4. Find the smallest positive number $c$ such that for any integer $n \geqslant 4$, and any set $A \subseteq\{1,2, \cdots, n\}$, if $|A|>c n$, then there exists a function $f: A \rightarrow\{1,-1\}$, satisfying $\left|\sum_{a \in A} f(a) \cdot a\right| \leqslant 1$.
First, when $n=6, A=\{1,4,5,6\}$, there does not exist a function $f$ that meets the requirements (the minimum difference of the sum of elements in $A$ is 2). At this time, $|A|=\frac{2}{3} n$, so when $|A| > c\frac{2}{3} n$, there exists a function $f$ that meets the requirements.

Lemma 1: Let $x_{1} \leqslant x_{2} \leqslant \cdots \leqslant x_{m}$ be $m (m \geqslant 2)$ positive integers, and $x_{1}+x_{2}+\cdots+x_{m} \leqslant 2 m-1$. Then for $i=2,3, \cdots, m$, we have $x_{i}-\left(x_{1}+x_{2}+\cdots+x_{i-1}\right) \leqslant 1$. Proof by induction on $m$.

When $m=2$, $x_{1}+x_{2} \leqslant 3 \Rightarrow x_{1}=x_{2}=1$ or $x_{1}=1, x_{2}=2$, the conclusion is obviously true. Assume the conclusion holds for $m \leqslant k$, then for $m=k+1$,
$$
x_{k+1}-\left(x_{1}+x_{2}+\cdots+x_{k}\right)=\left(x_{1}+x_{2}+\cdots+x_{k}+x_{k+1}\right)-2\left(x_{1}+x_{2}+\cdots+x_{k}\right)
$$
$\leqslant 2 k+1-2(1+1+\cdots+1)=2 k+1-2 k=1$
For $2 \leqslant i \leqslant k$, if $x_{k+1}=1$, then $x_{1}=x_{2}=\cdots=x_{k}=1$, the conclusion is obviously true;
If $x_{k+1} \geqslant 2 \Rightarrow x_{1}+x_{2}+\cdots+x_{k}=\left(x_{1}+x_{2}+\cdots+x_{k}+x_{k+1}\right)-x_{k+1}$
$\leqslant 2 k+1-2=2 k-1$, then by the induction hypothesis, for $2 \leqslant i \leqslant k$, we have $x_{i}-\left(x_{1}+x_{2}+\cdots+x_{i-1}\right) \leqslant 1$, i.e., the conclusion holds for $m=k+1$.
By the principle of induction, Lemma 1 is proved.

Lemma 2: Let $x_{1} \leqslant x_{2} \leqslant \cdots \leqslant x_{m}$ be $m (m \geqslant 1)$ positive integers, and $x_{1}+x_{2}+\cdots+x_{m} \leqslant 2 m-1$. Then for $k=1,2, \cdots, m$, define $\delta_{k}$ as follows:
$$
\delta_{m}=-1, \delta_{k}=\left\{\begin{array}{l}
-1, \delta_{m} x_{m}+\delta_{m-1} x_{m-1}+\cdots+\delta_{k+1} x_{k+1} \geqslant 0, \\
1, \delta_{m} x_{m}+\delta_{m-1} x_{m-1}+\cdots+\delta_{k+1} x_{k+1} < 0
\end{array}\right.
$$
We need to show that $\left|\delta_{1} x_{1}+\delta_{2} x_{2}+\cdots+\delta_{m} x_{m}\right| \leqslant 1$.

Proof: We use induction on $m$.
When $m=1$, $\delta_{1} x_{1} = -x_{1} \leqslant 1$ since $x_{1} \leqslant 1$.
Assume the conclusion holds for $m \leqslant k$, then for $m=k+1$,
If $\delta_{k+1} x_{k+1} \geqslant 0$, then $\delta_{k+1} = -1$ and $\delta_{1} x_{1} + \delta_{2} x_{2} + \cdots + \delta_{k+1} x_{k+1} = \delta_{1} x_{1} + \delta_{2} x_{2} + \cdots + \delta_{k} x_{k} - x_{k+1} \leqslant 1 - x_{k+1} \leqslant 1$.
If $\delta_{k+1} x_{k+1} < 0$, then $\delta_{k+1} = 1$ and $\delta_{1} x_{1} + \delta_{2} x_{2} + \cdots + \delta_{k+1} x_{k+1} = \delta_{1} x_{1} + \delta_{2} x_{2} + \cdots + \delta_{k} x_{k} + x_{k+1} \geqslant -1 + x_{k+1} \geqslant -1$.
Thus, $\left|\delta_{1} x_{1} + \delta_{2} x_{2} + \cdots + \delta_{k+1} x_{k+1}\right| \leqslant 1$.
By the principle of induction, Lemma 2 is proved.

(1) When $|A|$ is even, let $|A|=2m$. Let the set $A=\left\{a_{1}, a_{2}, \cdots, a_{2m}\right\}$, and $a_{1} < a_{2} < \cdots < a_{2m}$. Define $x_{i}=a_{2i}-a_{2i-1}$ for $i=1,2,\cdots,m$. Then $x_{1} \leqslant x_{2} \leqslant \cdots \leqslant x_{m}$ are $m$ positive integers. Since $|A| > \frac{2}{3} n \Rightarrow n \leqslant 3 m-1$,
Notice that $n \geqslant 4 \Rightarrow m \geqslant 2$, then $\sum_{i=1}^{m} x_{i}=\sum_{i=1}^{m} b_{i}=\sum_{i=1}^{m} a_{2 i}-\sum_{i=1}^{m} a_{2 i-1}$
$=a_{2 m}-a_{1}+\sum_{i=1}^{m-1} a_{2 i}-\sum_{i=2}^{m} a_{2 i-1}=a_{2 m}-a_{1}+\sum_{i=1}^{m-1} a_{2 i}-\sum_{i=1}^{m-1} a_{2 i+1}$
$=a_{2 m}-a_{1}-\sum_{i=1}^{m-1}\left(a_{2 i+1}-a_{2 i}\right) \leqslant(3 m-1)-1-(m-1)=2 m-1$,
By Lemma 2, there exist $\delta_{i} \in\{1,-1\}(1 \leqslant i \leqslant m)$, such that $\left|\delta_{1} x_{1}+\delta_{2} x_{2}+\cdots+\delta_{m} x_{m}\right| \leqslant 1$.
Thus, there exists a function $f: A \rightarrow\{1,-1\}$, satisfying the requirements.

(2) When $|A|$ is odd, let $|A|=2m-1$. Let the set $A=\left\{a_{1}, a_{2}, \cdots, a_{2m-1}\right\}$, and $a_{1} < a_{2} < \cdots < a_{2m-1}$. Define $x_{i}=a_{2i-1}-a_{2i-2}$ for $i=2,3,\cdots,m$. Then $x_{1} \leqslant x_{2} \leqslant \cdots \leqslant x_{m}$ are $m$ positive integers. Since $|A| > \frac{2}{3} n \Rightarrow n \leqslant 3 m-2$, notice that $n \geqslant 4 \Rightarrow m \geqslant 2$, then $\sum_{i=1}^{m} x_{i}=\sum_{i=1}^{m} b_{i}=a_{1}+\sum_{i=2}^{m} a_{2 i-1}-\sum_{i=2}^{m} a_{2 i-2}$ $=a_{2 m-1}+\sum_{i=1}^{m-1} a_{2 i-1}-\sum_{i=1}^{m-1} a_{2 i}=a_{2 m-1}-\sum_{i=1}^{m-1}\left(a_{2 i}-a_{2 i-1}\right)$
$\leqslant(3 m-2)-(m-1)=2 m-1$, by Lemma 2, there exist $\delta_{i} \in\{1,-1\}(1 \leqslant i \leqslant m)$, such that $\left|\delta_{1} x_{1}+\delta_{2} x_{2}+\cdots+\delta_{m} x_{m}\right| \leqslant 1$. Thus, there exists a function $f: A \rightarrow\{1,-1\}$, satisfying the requirements.

In summary, when $c=\frac{2}{3}$, there exists a function $f: A \rightarrow\{1,-1\}$, such that $\left|\sum_{a \in A} f(a) \cdot a\right| \leqslant 1$.