Question Author
Consider the formula as DOU= (2c+2-h-x+n)/2 . Now Degree of unsaturation is nothig but the total number o pi bonds and rings that an compund has. Now to convert a saturated molecue to have a pi band, it needs to give uo 2 hydrogen atoms. And a fully saturated molecule will have structure of C(n)H(2n+2). So removing a pair of hydrogen leads to one dgree of unsaturation. Chlorine(monovalent) and other halogens behave in the same manner as hydrogen so they are also subtratcted. Nitreogen(trivalent) needs three bonds so it will add to the requirement of a hydrogen, so it is added. Finally presence of oxygen and other divalent atoms is not important because they do not change the number of hydrogens until a pi bond is formed. And since you already count the total number of hydrogens, the effect is given. For further clarity see a video by Leaf4sci on her youtube channel.