Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

186 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Boruvka's Algorithm

Test

An implementation of Boruvka's algorithm to find a minimum spanning tree in a graph.

Link to narrated video demonstration on YouTube.

Example

image
stdout (Terminal Output)
Finding MST with Boruvka's algorithm:
Vertices: [0, 1, 2, 3, 4, 5, 6, 7, 8]
Edges (node1, node2, weight):
    (0, 1, 4)
    (0, 6, 7)
    (1, 2, 9)
    (1, 6, 11)
    (1, 7, 20)
    (2, 3, 6)
    (2, 4, 2)
    (3, 4, 10)
    (3, 5, 5)
    (4, 5, 15)
    (4, 7, 1)
    (4, 8, 5)
    (5, 8, 12)
    (6, 7, 1)
    (7, 8, 3)

Iteration 1:
Current MST edges: []
Current MST Weight: 0
Added edge 0 - 1 with weight 4 to MST.
Added edge 2 - 4 with weight 2 to MST.
Added edge 3 - 5 with weight 5 to MST.
Added edge 4 - 7 with weight 1 to MST.
Added edge 6 - 7 with weight 1 to MST.
Added edge 7 - 8 with weight 3 to MST.

Iteration 2:
Current MST edges: [(0, 1, 4), (2, 4, 2), (3, 5, 5), (4, 7, 1), (6, 7, 1), (7, 8, 3)]
Current MST Weight: 16
Added edge 0 - 6 with weight 7 to MST.
Added edge 2 - 3 with weight 6 to MST.

MST found with Boruvka's algorithm.
MST edges (node1, node2, weight):
    (0, 1, 4)
    (0, 6, 7)
    (2, 3, 6)
    (2, 4, 2)
    (3, 5, 5)
    (4, 7, 1)
    (6, 7, 1)
    (7, 8, 3)
MST weight: 29

Usage

Installing Dependencies

Install uv if you haven't already.

Run the following command from the project root directory:

uv sync --dev

Running the Application

Run the following command from the project root directory:

uv run python -m src.boruvkas_algorithm.boruvka

Running Tests

Run the following command from the project root directory:

uv run pytest -v

About

An implementation of Boruvka's algorithm to find a minimum spanning tree in a graph.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages