Information dynamics algorithm for detecting communities in networks