To do so, you need to know in advance the atoms by type (carbon, hydrogen, nitrogen, etc.), their number, and their valence. The later states how many bonds an atom may share with an adjacent atom. In your example, you consider hydrogen (only one bond), oxygen (up to two), and carbon (up to four).
You then introduce a constraint how these atoms are connected with each other. In the examples above, for example, you seem to use an explicit constraint; in the hydroxyl ($\ce{-OH}$) group oxygen binds to hydrogen, but this ensemble binds to carbon only via oxygen. An implicit constraint one may infer from the two illustrations you share is that you do not allow the formation of cycles for non-hydrogen atoms. Instead, you want to have them as chain.
Now to put this into perspective (literally), chemists convened how to draw molecular structures e.g., on paper while these are 3D objects. This is importance because often it does not suffice to know which atom binds to the next atom (constitutional isomer), but the spatial arrangement around e.g., carbon atoms (chirality, stereoisomers). Each of these levels is a potential pitfall for the exhaustive generation of the isomers possible; both for chemists who need training on this as well as for computer programs. Some generator programs (implicitly/explicitly) do not consider all of these levels.
In the examples shown by you, molecular symmetry reduces the number of isomers possible. On paper, you might assume that any of the six hydrogen atoms at the two terminal carbon atoms may be replaced by a $\ce{-OH}$ group which already would lead to six isomers. No, this is not the case as they are all symmetry equivalent:
Assume the three carbon atoms - symbolized by dark spheres - as a plane; the hydroxyl group (oxygen symbolized by a red, hydrogen by white spheres) may be once at this level, or above, or below. But the whole molecule (propan-1-ol) may be rotated; the rotation of the very same group binding to $\ce{-OH}$ may be again above, at level, or below of this imaginary plane.
The second structure you drew is a constitutional isomer of the first one, it is propan-2-ol. You might think that it would matter if the hydrogen replaced by $\ce{-OH}$ is above of this level of the three carbon atoms. Again, because of symmetry, this is not the case, the two are symmetry equivalent and you have to consider only one isomer:
Thus, if you are set to look for the isomers of alcohols with the sum formula $\ce{C3H8O}$, there are only two isomers in total.
There would be a third isomer, an ether, if one allows for the joining $\ce{CH3CH2-O-CH3}$: