Some Examples of Sheaves on Varieties (Hartshorne's Exercise II.1.21) I'm currently working on exercises in Hartshorne's Algebraic Geometry and coming up with some questions on Exercise II.1.21. I'll briefly restate the exercise and ask questions along with the description.

Let $X$ be a variety over an algebraically closed field $k$ and let $\mathcal{O}_X$ be the sheaf of regular functions on $X$.

Question 1: Can we define the sheaf of regular functions $\mathcal{O}_X$ on an arbitary algebraic sets $X$ (NOT necessarily be irreducible)? Maybe we can define a regular function on an open subset $U$ of $X$ just as the functions $f: U \rightarrow k$ that are regular at every point $p \in U$ (the same as the definition of regular functions on a variety) and collect them in a set $\mathcal{O}_X(U)$. It seems that $[U \mapsto \mathcal{O}_X(U)]$ remains to be a sheaf?

(a) Let $Y$ be a closed subset of $X$. For each open set $U \subset X$, let $\mathcal{I}_Y(U)$ be the ideal containing $\mathcal{O}_X(U)$ consisting of those regular functions which vanish at all points of $Y \cap U$. Show that the presheaf $[U \mapsto \mathcal{I}_Y(U)]$ is a sheaf. ......

Question 2(EDITED): I have "proved" this. In the "proof", I haven't used the assumption that "$Y$ is closed in $X$". So is it true that $\mathcal{I}_Y$ is a (well-defined) sheaf for any subset $Y$ of $X$ (NOT necessarily be closed)? Here is my "proof":
Attempt 2 (Proof): $\mathcal{I}_Y: [U \mapsto \mathcal{I}_Y(U)]$ is a presheaf, with the restriction map given by the usual restriction of regular functions.
For the first sheaf condition, let $U$ be any open subset of $X$, and $\{ U_i\}_{i \in I}$ be one of its open cover. Let $s \in \mathcal{I}_Y(U)$, such that $s\vert_{U_i} = 0 \in \mathcal{I}_Y(U_i)$ for all $i \in I$, which means that $s$ is the zero regular function defined on $U_i$. Then since $\{ U_i\}_{i \in I}$ is an open cover of $U$, $s$ is the zero regular map defined on the entire $U$, which clearly vanishes at all points of $U$. So, $s = 0 \in \mathcal{I}_Y(U)$.
For the second sheaf condition, with the same notation, let $s_i \in \mathcal{I}_Y(U_i)$ for all $i \in I$ satisfying the compatibility condition, i.e. $s_i \vert_{U_{ij}} = s_j \vert_{U_{ij}}$, for all $i,j \in I$. Then we can glue then together to obtain a regular function $s \in \mathcal{O}_X(U)$, such that $s\vert_{U_i} = s_i$ for all $i \in I$. Now we shall show that $s \in \mathcal{I}_Y(U)$. Let $P \in Y \cap U$. Since $\{ U_i\}_{i \in I}$ is an open cover of $U$, there exists $i_0 \in I$, such that $P \in Y \cap U_{i_0}$. Now since $s\vert_{U_{i_0}} = s_{i_0}$, we have $s(p) = s \vert_{U_{i_0}} (p) = s_{i_0}(p) = 0$, where the last equality holds because $s_{i_0} \in \mathcal{I}_Y(U_{i_0})$. Here $p$ is arbitarily chosen, and hence $s$ vanishes at all points $P \in Y \cap U$. So, $s \in \mathcal{I}_Y(U)$.  $\blacksquare$

(b) If $Y$ is a subvariety, then the quotient sheaf $\mathcal{O}_X / \mathcal{I}_Y$ is isomorphic to $i_{\ast}(\mathcal{O}_Y)$, where $i: Y \rightarrow X$ is the inclusion, and $\mathcal{O}_Y$ is the sheaf of regular functions on $Y$.

I have proved this:
Attempt (Proof): Let $i: Y \rightarrow X$ be the inclusion, and for any open subset $U$ of $X$,
$$
i_{\ast}(\mathcal{O}_Y)(U) := \mathcal{O}_Y(i^{-1}(U)) = \mathcal{O}_Y(U \cap Y).
$$
So, we can define a sheaf morphism $i^{\sharp}: \mathcal{O}_X \rightarrow i_{\ast}(\mathcal{O}_Y)$ as
$$
i^{\sharp}(U): \mathcal{O}_X(U) \rightarrow i_{\ast}(\mathcal{O}_Y)(U)= \mathcal{O}_Y(U \cap Y), \quad f \mapsto f\vert_{U \cap Y}.
$$
We can check that this is indeed a sheaf morphism. By the construction, the sheaf $\mathcal{I}_Y$ (it is indeed a sheaf, as shown in (a)) is the kernel of the morphism $i^{\sharp}$.
Now, we need to show the surjectivity of $i^{\sharp}$. To do that, we turn to the maps induced on stalks:
$$
i^{\sharp}_p: (\mathcal{O}_X)_p \rightarrow (i_{\ast}(\mathcal{O}_Y))_p = \mathcal{O}_Y(\cdot \cap Y)_p.
$$
There are two cases. (1) When $P \not\in Y$, then there exists an open neighborhood of $P$, not intersecting $Y$. (Here maybe we are using $Y$ is closed) So $(i_{\ast}(\mathcal{O}_Y))_p=0$, and hence $i^{\sharp}_p$ is surjective. (2) When $P \in Y$, consider a germ $t_p \in (i_{\ast}(\mathcal{O}_Y))_p$ represented by $\langle t, U \rangle$, where $t \in i_{\ast}(\mathcal{O}_Y)(U) = \mathcal{O}_Y(U \cap Y)$, and $P \in U$. This germ also represents an element in $(\mathcal{O}_X)_p$. Hence $i^{\sharp}_p$ is surjective.
Combining the two paragraphs above, we obtain that $i_{\ast}(\mathcal{O}_Y) = \mathcal{O}_X / \mathcal{I}_Y$ as desired. Furthermore, we obtain a short exact sequence:
$$
0 \longrightarrow \mathcal{I}_Y \longrightarrow \mathcal{O}_X \longrightarrow i_{\ast}(\mathcal{O}_Y) \longrightarrow 0 . \quad \quad (\star)
$$ $\blacksquare $
In (c), Hartshorne asked

(c) Now let $X = \mathbb{P}^1$ and let $Y$ be the union of two distinct points $P , Q \in X$. Then there is an exact sequence of sheaves on $X$: $$  0 \longrightarrow \mathcal{I}_Y \longrightarrow \mathcal{O}_X \longrightarrow i_{\ast}(\mathcal{O}_P) \oplus i_{\ast}(\mathcal{O}_Q)  \longrightarrow 0  \quad \quad  (\star \star)$$ ......

Question 3: Some online solution manuals claimed that this exact sequence can be obtained directly using the exact sequence $(\star)$, by applying $X = \mathbb{P}^1$ and $Y = \{ P , Q \}$. But it seems that $Y= \{ P , Q \}$ is not irreducible, hence not a subvariety of $X$. So why can we use (b) directly?
Attempt 3 (The source of my questions in this post): However, in the proof of (b) above, it seems that we did NOT use the fact that $Y$ is irreducible, except that when we define the sheaf $\mathcal{O}_Y$, $Y$ need to be irreducible. This is the source of my Question 1. i.e. if we can throw away the restriction that $Y$ is irreducible and define $\mathcal{O}_Y$ as well (described in Question 1), then $\mathcal{O}_Y$ is well-defined (for merely a closed set), then we can use the short exact sequence $(\star)$ directly, although $Y = \{P, Q \}$ is not irreducible.
Here, If all my attempts above turn out to be wrong, then I hope to prove (c) directly:
Question 4: If we cannot use the result of (b) directly, I'm trying to throw away what we have proved so far and prove the sequence $ (\star \star)$ is exact directly. A tricky point is to constuct a surjective sheaf morphism
$$
\beta: \mathcal{O}_X \rightarrow i_{\ast}(\mathcal{O}_P) \oplus i_{\ast}(\mathcal{O}_Q).
$$
And I am wondering how to construct this map?
Attempt 4: My attempt is to define on each open set $U \subset X$ the map
$$
\beta(U): \mathcal{O}_X(U) \rightarrow i_{\ast}(\mathcal{O}_P)(U) \oplus i_{\ast}(\mathcal{O}_Q)(U)
$$
by sending $f$ to $(f,0), (0,f), (f,f)$ or $(0,0)$ if $P \in U, Q \not\in U$; $P \not\in U, Q \in U$; $P \in U, Q \in U$ and $P \not\in U, Q \not\in U$ accordingly, and check that the induced map on stalks $\beta_p$ are surjective for all $p \in X$, but I haven't managed to do so.
Sorry for such a long post and thank you all for commenting and answering them :)
 A: After some discussion with my classmates, I have figured some of the questions out. So here I hope to share my understandings. Sorry if there are any mistakes.
For Question 1: we can indeed define the sheaf of regular functions on any algebraic sets (not necessarily irreducible). A regular function on an open subset $U$ of an algebraic set $X$ can be defined as a function $f: U \rightarrow k$ such that $f$ is regular at every point of $U$. Then we may check that this indeed make $\mathcal{O}_X$ a sheaf.
For Question 2: Indeed we do not need the fact that $Y$ is closed in the proof of (a) in the post. However, we need the closedness of $Y$ to establish the exact sequence of (b). The exact sequence is vital and hence we insist on putting the requirement of closedness at the begining.

Maybe there are other (more reasonable) reasons for this when we define the ideal sheaf in Section 2.5 of Hartshorne? I haven't learnt that much though.

For Question 3: Since the answer of Question 1 is positive, we can directly apply $X = \mathbb{P}^1_k$ and $Y=\{P, Q \}$ in the exact sequence of (b).
For Question 4: By the above explanation of Question 3, we do not need Question 4 answered. Yet if we really hope to dig out what the map $\beta$ is, we shall go back in the proof of (b) (as listed in the post) and write it out in the context of (c).
Sorry for any possible mistakes and misunderstandings!
