compact set always contains its supremum and infimum

Let $K$ be a compact subset of $\mathbb R$. Prove that $\sup K$ and $\inf K$ exist and are in $K$.

My approach: As $K$ is compact, it is bounded. So $\sup K$ and $\inf K$ exists. The reason is that:

Since $K$ is compact, there exist $k_1, \cdots , k_n \in \mathbb R$ such that

$$K \subset \bigcup_{j=1}^n (-k_j,k_j)$$

If $N = \max\{k_1,\cdots, k_n\}$, then $K$ is a subset of $(-N,N)$. Hence $K$ is bounded.
since $K$ is bounded by $-N$ and $N$, $\sup K$ and $\inf K$ exists.

Is this good enough? Is boundedness guaranteed the existence of supremum and infimum?

Solutions Collecting From Web of "compact set always contains its supremum and infimum"

Generally, it’s easier to work with open sets than with closed sets. Open sets have less structure: all their points are interior. Closed sets may have two kinds of points: interior and boundary.

So, I would rather look at $\mathbb R\setminus K$. If $\sup K\in \mathbb R\setminus K$, then by openness, there is an interval $(a,b)$ contained in $\mathbb R\setminus K$ and containing $\sup K$. Show that $a$ is an upper bound for $K$, and you have a contradiction.

Is closed condition necessary for $\inf$ and $\sup$ [to be contained in the set]?

It’s essential for the proof (i.e., we can’t just drop it), but it’s not necessary in the sense that some sets contain their $\inf$ and $\sup$ without being closed. For example, $[-2,1) \cup (1,2]$.

A compact set in a metric set is bounded: cover the set by balls of fixed radius $r$, then find a finite subcover by balls of radius $r$. Then consider d: $K \times K \rightarrow \mathbb R$ takes a max $M$ and a min $m$ since $d$ is a continuous function on a compact set . Now consider $d (0,K) : {0} \times K \rightarrow \mathbb R $ , another continuous, Real-valued function on a compact set, which takes a max M’, and a min m’. Then the ball centered at $0^n$ with radius 2(M+M’) contains $K$.

Now, for the limit points. For every connected component of $K$ that has more than a singleton, both $SupS, InfS$ are limit points of $S$. If they were not, and there is $r$ with $B(x,r) \cap K =\ $ {} , then $K$ is not connected. In $R^n$ , compact implies closed and bounded (tho the argument in the above paragraphfor boundedness of compact in metric space still holds.) Since , in this case SupS, LimS are limit points, and a closed set contains all its limit points, a compact set contains its sup and Inf. In the case $K$ is not connected, this still holds.

As $K$ is compact, we have that $K$ is bounded. So $\sup K$ and $\inf K$ exists. By definition $\sup K$, for every $n \in N$ exists $x_n \in K$ such that $\sup K- x_n<1/n$ then $\sup K = \lim x_n$ with $x_n \in K$, as K is closed follows that $\sup K \in K$. To inf is analogous.
Ps: Compact ⇒ closed and bounded.