Skip to content

Commit

Permalink
Cycles and graph density are private
Browse files Browse the repository at this point in the history
  • Loading branch information
brunolnetto committed Jan 14, 2022
1 parent 3c74b09 commit e3cbca9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/data-structures/graph/Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { cyclicSort, getAllIndexes } from '../../utils/arrays/arrays.js'

export default class Graph {
#cycles;
#density;

/**
* @param {boolean} isDirected
Expand All @@ -10,12 +11,21 @@ export default class Graph {
this.vertices = {};
this.edges = {};
this.isDirected = isDirected;
this.#cycles = [];
this.#cycles = [];
this.#density = 0;
}

get cycles(){
return this.allCycles();
}
return this.cyclicPaths();
}

get density(){
let n_vertices = this.getNumVertices();
let n_dense = n_vertices*(n_vertices-1)/2;
let n_edges = this.getAllEdges().length;

return n_edges/n_dense;
}

/**
* @param {GraphVertex} newVertex
Expand Down

0 comments on commit e3cbca9

Please sign in to comment.