How to write an algorithm which doubles stack in order to accommodate for new members where push is in constant time in the worst case?
I don't think that it is possible to push an element to a full array-based stack in worst case $\mathcal{O}(1)$ time. However, you can rest assured that each push runs in constant amortized time whenever you multiply the length of the full array by a factor of $q &gt; 1$ (like you do; $q = 2$ in your case). This is why:

Suppose the initial array capacity is $m$. Next we choose $q &gt; 1$ such that $\lfloor qm \rfloor &gt; m$, or namely, $q$ must be sufficiently large in order to trigger an array expansion.

Suppose the total accumulated work of adding $n$ elements to the stack is 

$$W = m + mq + mq^2 + \dots + \overbrace{mq^k}^n$$. 

We require $k$ to be the smallest integer such that $mq^k \geq n$, which leads us to the following inequalities:

$$
\begin{aligned}
mq^k &amp;\geq n \\
q^k &amp;\geq \frac{n}{m} \\
\log_q q^k &amp;\geq \log_q \Bigg( \frac{n}{m} \Bigg) \\
k &amp;\geq \log_q n - \log_q m.
\end{aligned}
$$

Since $k$ is required to be the smallest integer satisfying the above inequality, we can set $k = \lceil \log_q n - \log_q m \rceil$. Also,

$$
\begin{align}
qW = mq + mq^2 + \dots + mq^{k + 1} &amp;\Rightarrow W - qW = m(1 - q^{k+1}) \\
    &amp;\Rightarrow W = m\frac{1 - q^{k+1}}{1-q}.
\end{align}
$$

Since $k = \lceil \log_q n - \log_q m \rceil$, we obtain
$$
\begin{align}
W &amp;= m\frac{1 - q^{\lceil \log_q n - \log_q m \rceil + 1}}{1 - q} \\
  &amp;\leq m\frac{1 - q \cdot q^{\lceil \log_q n \rceil}}{} \\
  &amp;\leq m \frac{1 - q \cdot q^{\log_q n + 1}}{1- q} \\
  &amp;= m \frac{1 - q^2n}{1 - q}.
\end{align}
$$

Now we have that

$$
\begin{align}
\frac{1}{n} W &amp;\leq \frac{1}{n} \Bigg[ m \frac{1-q^2n}{1-q} \Bigg] \\
              &amp;= \frac{1}{n} \Bigg[ \frac{m}{1-q} - \frac{nmq^2}{1-q} \Bigg] \\
              &amp;= \frac{m}{(1-q)n} - \frac{mq^2}{1-q} \\
              &amp;\leq \frac{m}{1-q} - \frac{mq^2}{1-q} \\
              &amp;= \frac{m(1-q^2)}{1-q},
\end{align}
$$
which is constant since $m$ and $q$ are fixed parameters independent of $n$.