Cardinality of strict extrema of a real function

I recently encountered a problem seeking to prove that a real function can only have a maximum number of #$\mathbb{N}$ strict maximums. It may be that I have copied the problem improperly since there are a few solutions in the continuous case but nevertheless I could not prove it in the general case (nor provide a counterexample) so any help would be welcome.

One of the key arguments in the continuous case seems to be the fact that such points of strict extrema are isolated and for example the function $f(x) = \mathbb{1}_{\mathbb{Q} \cap(0,1)} \cdot \frac{1}{q}$ (where $x=p/q$ reduced) has no isolated extrema (but still has an enumerable number of strict extrema).

Furthermore I tried to look into the Cantor set but the problem is that its points are not isolated, which makes me believe that a possible construction of such a function might require the axiom of choice.

• i have seen (and answered) a similar question before on MSE I would (and you should) search for an answer already posted. See question math.stackexchange.com/q/1544495 and this answer math.stackexchange.com/q/1545379 Better yet see this answer math.stackexchange.com/q/1547568 – Mirko Apr 26 '16 at 1:48
• @Mirko We did arrive at that conclusion presented in the last link but without any further success. – Marko Karbevski Apr 26 '16 at 16:13
• @MarkoKarbevski I posted an answer to clarify what I meant, even if I believe it is contained in (or could be deduced from) the answers that I indicated in my comment above. – Mirko May 3 '16 at 5:03

I believe the answer is contained in the links provided in my comment above, but I will provide the argument here. Even if the function $f$ is not continuous, the mere definition of strict maximum (my understanding is that what is meant is a strict local maximum) involves neighborhoods, and that allows for a proof that there are at most $\#\mathbb N$ (i.e. at most countably many) strict local maxima.
Suppose that $f:\mathbb R\to\mathbb R$ had uncountably many strict local maxima. Let $X=\{x\in\mathbb R:f$ has a strict local maximum at $x\}$. In other words, $x\in X$ if and only if there is some $\varepsilon_x>0$ such that $f(x)>f(y)$ whenever $y\in(x-\varepsilon_x,x+\varepsilon_x)\setminus\{x\}$. Equivalently, $x\in X$ if and only if there is some positive integer $n_x$ such that $f(x)>f(y)$ whenever $y\in(x-\frac1{n_x},x+\frac1{n_x})\setminus\{x\}$. For each $x\in X$ fix $n_x$ as above. Let $X_n=\{x\in X:n_x=n\}$. Then $X=\bigcup_{n\in\mathbb N} X_n$, hence if $X$ were uncountable there is $n$ such that $X_n$ is uncountable.
There must be a point $z\in X_n$ such that every neighborhood of $z$ intersects $X_n$ in uncountably many points. (Indeed if no such $z$ exists, then every $x\in X_n$ would have a countable relative neighborhood, and using that every subspace of $\mathbb R$ has a countable basis, and is hence Lindelof, it would follow that $X_n$ were countable.) In particular we could take distinct $x,y\in X_n$, each distance less than $\frac1{2n}$ to $z$, and hence distance from $x$ to $y$ is less than $\frac1n$. Since both $x$ and $y$ belong to $X_n$ it follows that $f(x)>f(y)$ and $f(y)>f(x)$, a contradiction, which shows that $X$ must be countable. (This could be edited further: I didn't really use that $z\in X_n$, so it could have been enough to pick $z\in\mathbb R$ which is an accumulation point of $X_n$. But I used that these local maxima are strict, otherwise a constant function would provide a counterexample.)