% \subsection{Variance Estimation Algorithm}
% \label{subssec:variance_estimation_algorithm}

\begin{algorithm}[H]
\caption{$\ojavarest(\{X_{i}\in \mathbb{R}^{d}\}_{i \in [n]},  \delta, \vmain, \eigengap)$}
\label{alg:variance_estimation}
\begin{algorithmic}[1]
\State \textbf{Input:} Data $\mathcal{D}_n := \{X_{i}\in \mathbb{R}^{d}\}_{i \in [n]}$, failure probability $\delta\in (0,1)$, unit vector $\vmain$, eigengap $\eigengap$

\State \textbf{Output:} Estimates $\left \{ \hat{\gamma}_k \right \}_{k \in [d]}$ of $\{\V_{kk}\}_{k \in [d]}$
\State $m_{1} \gets 8\log(d/\delta), \;  m_{2} \gets \log n, \; B \gets n/(m_1m_2) $.
\For{$\ell \in [m_1]$}
    \For{$j \in [m_2]$}
        \State $\mathcal{D}_{\ell,j} \gets \left\{X_{B( m_2(\ell-1) + (j-1)) + t}\right\}_{t \in [B]}$
        \State $g \gets \mathcal{N}(0, I), \quad u \gets g/\norm{g}_2$
        \State $\hat{v}_{\ell,j} \gets \Oja\bb{\mathcal{D}_{\ell,j}, \eta_{B}, u_0}$
        % \State \rd $\hat{v}_{j} \gets \successboost\bb{\mathcal{D}_{i,j}, \voja, \delta}$ \bk
    \EndFor
    % \State $\hat{\sigma}^{2}_{i} \gets \sum_{j \in [m_2/2]} \dfrac{\min\left\{|e_{k}^{\top}(\hat{v}_{2j} - \hat{v}_{2j-1})|, |e_{k}^{\top}(\hat{v}_{2j} + \hat{v}_{2j-1})|\right\}^{2}}{m_{2}}$
    \For{$k \in [d]$}
        \State $\hat{\sigma}^{2}_{\ell, k} \gets \frac{\sum_{j \in [m_2]} \bb{e_k^\top\bb{\hat{v}_{\ell,j} - \bb{\vmain^\top \hat{v}_{\ell,j}} \vmain}}^2}{m_2}$
    \EndFor
\EndFor
\For{$k \in [d]$}
    \State $\hat{\gamma}_k \gets \frac{1}{\eta_B (\lambda_1 - \lambda_2)} \median\bb{\left\{\hat{\sigma}^{2}_{\ell, k}\right\}_{\ell \in [m_1]}}$
\EndFor
\State \Return $\left \{ \hat{\gamma}_k \right \}_{k \in [d]}$
\end{algorithmic}
\end{algorithm}


% \textcolor{red}{
% \begin{algorithm}[H]
% \caption{$\ojavarest(\{X_{i}\in \mathbb{R}^{d}\}_{i \in [n]}, \delta, \epsilon, k)$}
% \label{alg:variance_estimation_new}
% \begin{algorithmic}[1]
% \State \textbf{Input:} Data $\mathcal{D}_n := \{X_{i}\in \mathbb{R}^{d}\}_{i \in [n]}$, failure probability $\delta\in (0,1)$, error tolerance $\epsilon\in (0,1)$, coordinate $k \in [d]$
% \State \textbf{Output:} $\hat{\gamma}_{n}$ such that with probability at least $1-\delta$, 
% \bas{\hat{\gamma}_{n}\in\bigl((1-\epsilon)\sigma_n^2,(1+\epsilon)\sigma_n^2\bigr) \text{ where } \sigma_n^2:=\operatorname{Var}(\voja(\mathcal{D}_n))}
% \State $n_1$
% \State $m_{1} \gets 10\log(1/\delta), \;  m_{2} \gets 10\log(1/\delta), \; B \gets n/(m_1m_2) $.
% \For{$i \in [m_1]$}
%     \For{$j \in [m_2]$}
%         \State $\mathcal{D}_{i,j} \gets \left\{X_{B( m_2(i-1) + (j-1)) + t}\right\}_{t \in [B]}$
%         \State $\hat{v}_{j} \gets \successboost\bb{\mathcal{D}_{i,j}, \voja, \delta}$
%     \EndFor
%     \State $\hat{\sigma}^{2}_{i} \gets \sum_{j \in [m_2/2]} \dfrac{\min\left\{|e_{k}^{\top}(\hat{v}_{2j} - \hat{v}_{2j-1})|, |e_{k}^{\top}(\hat{v}_{2j} + \hat{v}_{2j-1})|\right\}^{2}}{m_{2}}$
% \EndFor
% \State $\hat{\gamma}_n \gets \median\bb{\left\{\hat{\sigma}^{2}_{i}\right\}_{i \in [m_1]}}$
% \State \Return $\hat{\gamma}_n$.
% \end{algorithmic}
% \end{algorithm}
% }