Morphological transition of ZnO nanostructures influenced by magnesium doping