Skip to content

Commit

Permalink
refac/Early return for graph connection
Browse files Browse the repository at this point in the history
  • Loading branch information
brunolnetto committed Feb 11, 2022
1 parent c89be86 commit 09ee311
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions data-structures/graph/Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,12 @@ export default class Graph {
isConnected(){
const n_vertices = this.getNumVertices();
const adjList = this.getAdjacencyList();
const edges = this.getAllEdges();

// If there are no edges in the graph, return true
if (edges.length == 0){
return true;
}

// Mark all the vertices as not visited
let visited = new Array(n_vertices);
Expand Down

0 comments on commit 09ee311

Please sign in to comment.