A graph is a mathematical structure that represents a collection of objects related to one another. Each object corresponds to…