all element graph and sort on the way