In class I was given this problem with solution. I was hoping someone could shed some light on them.
$\underline{Question}$
Is the set K RE (recursively enumerable)?
K = { $i$ | $P_{i}$ halts on input $i$ }
$\underline{Solution}$
For j = 1 to infinity:
For i = 1 to j:
Run program i on input i for j steps; if it halts, print i
(end for)
(end for)
The solution does not seem to make sense to me since the set K is undecidable and if you can list all the elements in K then you can list all the elements in $\bar{K}$, therefore the sets K and $\bar{K}$ should be decidable by their solution.
Also, the program should not halt (or move on to the next program) if it reaches a program $i$ that does not halt. Correct?
That you can list $K $ does not mean you can list its complement. Perhaps the thing to note to build your intuition is that the program is not listing the elements of $K $ in increasing order. Indeed, maybe program 20 halts on input 20 but only does it after several million steps, while program 19 doesn't halt on input 19 and program 21 halts on input 21 after 2 steps. What do you do to enumerate $\bar K $? If the elements of $K $ were being listed in order it would be easy: once a number larger than 20 is listed, you would know whether 20 is in $K $ (if it was already listed) or not ( in which case you list it in $\bar K $). But the way things are, 21 is listed quickly and you wait and wait and essentially decide 20 is never going to appear, and you should list it in $\bar K $, but then it shows up. And what about 19? At what point would you list it in $\bar K $?