create graph code with two utility function