Skip to content

Commit 59880ed

Browse files
committed
docs: add documentation of code
1 parent 9515348 commit 59880ed

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/graph/tree_center.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
//! Finds the center of a weighted tree using two depth-first searches (DFS).
2+
//!
3+
//! The algorithm works as follows:
4+
//!
5+
//! 1. Perform a first DFS to compute, for each node, the maximum distance
6+
//! to any descendant in its subtree (i.e., the deepest node below it).
7+
//!
8+
//! 2. Perform a second DFS to compute, for each node, the maximum distance
9+
//! to nodes outside its subtree (i.e., through its parent and other branches).
10+
//!
11+
//! For each vertex, the farthest node in the tree is either:
12+
//! - a descendant in its own subtree, or
13+
//! - a node reached by going up to its parent and then down another branch.
14+
//!
15+
//! The eccentricity of each node is the maximum of these two values.
16+
//! The center of the tree is the node that minimizes this eccentricity.
17+
//!
18+
//! This implementation works for weighted trees.
19+
120
use std::collections::HashMap;
221

322
use crate::data_structures::{graph::Graph, UndirectedGraph};

0 commit comments

Comments
 (0)