With molecular formula, how do I know if it linear or one element surrounded by other elements?
The formula is insufficient. Consider pentane, $\ce{C5H12}$, which occurs in straight and branched isomers, the extreme case being neopentane, in which the central carbon is linked only to four methyl groups.