Epistemic logic: in which worlds are the formulas true?

I have a question regarding the following:

I don't get both answers. I thought that question 1 was true in w2, w3, w4. But the answer does not show have w3. Why is that? Because the symbol says that it considers q to be true.

And for question 2: I thought that w2 and w4 were true. Because you ''know'' them via the other worlds. It seems to be that w3 is just false, so you can't know that P is true. And you certainly can not know that w5 and w1 are true, because there is no link to them or to themselves.

Can somebody please explain or reference something that makes this clear.

Thank you very much!

Recall the semantics for the diamond and the box: for an arbitrary pointed model $\langle M, w\rangle$ we have:

Definition 1. $\langle M, w\rangle \models \diamondsuit(\phi)$ $=_{def}$ $\exists v \in M$ s.t. $wRv$ and $\langle M, v\rangle \models \phi$.

Definition 2. $\langle M, w\rangle \models \Box(\phi)$ $=_{def}$ $\forall v \in M$ s.t. $wRv$, then $\langle M, v\rangle \models \phi$.

Armed with these definitions, you can rephrase your questions as follows:

Question 1. Which worlds $w \in M$ point to some world $v\in M$ s.t. $\langle M, v\rangle \models q$?

Answer. This gives us an algorithm to get the answer: for each $w \in M$, $w$ belongs to the answer set if and only if there is at least one arrow from $w$ to a world $v \in M$ that satisfies $q$. Does $\color{red}{w_1}$ point to a $q$-world? No. But $\color{green}{w_2}$ does. $\color{red}{w_3}$ also doesn't point to a $q$-world. But $\color{green}{w_4}$ does. Does $w_5$ point to...well, like $w_3$ it points to nothing, so it obviously can't point to a $q$-world. So we have $\{\color{green}{w_2},\color{green}{w_4}\}$.

Question 2. Which worlds $w \in M$ are s.t.: all worlds $v\in M$ they point to are s.t. $\langle M, v\rangle \models p$?

Answer. Similarly for this: for each $w \in M$, $w$ belongs to the answer set if and only if all the arrows from $w$ point to a world $v \in M$ that satisfies $p$. $w_1$ points only to $w_2$, which satisfies $p$, so $\color{green}{w_1}$ does. $w_2$ points to $w_4$, which satisfies $p$, but $w_2$ also points to $w_3$, which does not satisfy $p$, so $\color{red}{w_2}$ isn't in the answer set. $\color{green}{w_3}$ points to nothing, so vacuously all the worlds it points to satisfy $p$. For exactly the same reason $\color{green}{w_5}$ is also in the answer set. $w_4$ points to itself and $w_2$, which do satisfy $p$, but it also points to $w_3$, which does not, so $\color{red}{w_4}$ is not in the set. This gives us the answer: $\{\color{green}{w_1},\color{green}{w_3}, \color{green}{w_5}\}$.

An arrow from state A to state B seems to indicate that the state B is considered possible in state B. It is not required that the subject considers the true state to be possible. Now the states in which $q$ holds are $w_3$ and $w_4$. To get the states where $q$ is considered possible, we have to find the states in which some arrow points to $w_3$ or $w_4$. And these states are exactly $w_2$ and $w_4$.

The question is in which states $p$ is considered to be necessary. These are the states in which the subjects considers only states possible in which $p$ is true. Now $p$ is true in $w_1,w_2,w_4$. Now in $w_1$ only the state $w_2$ is considered to be possible, and at that stae $p$ holds. So $p$ is necessary at $w_1$. At $w_2$, both $w_4$ and $w_3$ are considered to be possible. Now $p$ is true in $w_4$ but not in $w_3$, so $p$ is not considered necessary at $w_2$. You can verify this for the other states similarly. The case of $w_5$ is slightly tricky. At $w_5$, no state is considerd possible. So the set of states considered possible is empty and $p$ holds in all states in the empty set vacuously.