Class: Graph

Graph()

Main Graph Class. Implements methods for adding vertices, edges, and finding the Minimum Spanning Tree (MST).

Constructor

new Graph()

Source:

Classes

Graph

Methods

addEdge(v1, v2, weight)

Adds a weighted edge between two vertices.

Parameters:
Name Type Description
v1 string

First vertex name.

v2 string

Second vertex name.

weight number

The weight/compatibility score of the edge.

Source:
Throws:

If one of the vertices is not found.

Type
Error

kruskalMST() → {Object}

Finds the Minimum Spanning Tree (MST) using Kruskal's algorithm.

Source:
Returns:

Returns { mst: Array, weight: number }.

Type
Object

primMST(startVertex) → {Object}

Finds the Minimum Spanning Tree (MST) using Prim's algorithm.

Parameters:
Name Type Description
startVertex string

The starting vertex for the traversal.

Source:
Returns:

Returns { mst: Array, weight: number }.

Type
Object