Abstract: This article proposes a weighted group algorithm of sensor network which considers density and residual energy of the node.By choosing the best weighted value,it ensures that the best performance node becomes the header.The density of nodes in each group is within a reasonable scope through controlling transmitting power of the node.The improved group algorithm optimizes header choosing,balances the energy consumption of the whole network and prolongs the lifetime of the network.Finally,the simulation verifies the effect of the group algorithm.