Solution (source code)

= Solution

Use <weighted decision stump optimization> with the convention $\operatorname{sign}(0)=+1$, and write $w_j=D((x_j,y_j))$. For each coordinate $i$, sort the examples by their $i$th coordinate and group all equal coordinate values. For a threshold between the $k$th and $(k+1)$st distinct values, the <decision stump> predicts $-1$ on the left and $+1$ on the right. Its weighted <misclassification risk> is
$$
\boxed{E_i(k)=\sum_{j\text{ left},\ y_j=+1}w_j
+\sum_{j\text{ right},\ y_j=-1}w_j.}
$$
Start with a threshold below the minimum observed value. Every prediction is then $+1$, and the initial error is $\sum_{y_j=-1}w_j$. Sweep the threshold from left to right. When it passes an entire group $G$ of equal coordinate values, that group's prediction changes from $+1$ to $-1$, so update
$$
\boxed{E\leftarrow E+\sum_{j\in G,\ y_j=+1}w_j-\sum_{j\in G,\ y_j=-1}w_j.}
$$
Record the smallest value and a threshold achieving it, including the final threshold above all observations, which predicts $-1$ everywhere on the sample. Representatives can be chosen strictly between successive distinct values; the two outer representatives are finite real numbers below the minimum and above the maximum.

Every threshold has exactly the same sample predictions as one of these representatives. In particular, if a threshold equals an observed value, the equality group is on the $+1$ side under the chosen <sign function> convention, which duplicates the representative immediately before that group. Thus the sweep includes every possible sample labelling by the stated <decision stump>. Repeating for all $n$ coordinates and returning the globally smallest error proves optimality.

Sorting costs $O(m\log m)$ per coordinate and the grouped sweep costs $O(m)$. The overall <time complexity> is
$$
\boxed{O(nm\log m),}
$$
with $O(m)$ working storage when coordinates are processed one at a time. Pre-sorted coordinate orders can be reused across repeated <AdaBoost> rounds, leaving $O(nm)$ work per round for changing weights. The paper allows only the orientation $\operatorname{sign}(x_i-b)$; reversing its polarity would enlarge the <hypothesis class> and is unnecessary here.