These codes are taken from NPTEL Social Networks Course and modified as on my experiments.