Skip to content

Conversation

@iampratik13
Copy link
Contributor

This PR introduces a complete and well-documented implementation of the Floyd–Warshall algorithm in R using an R6 class structure.

Overview

The FloydWarshall class computes shortest paths between all pairs of vertices in a weighted directed graph.
It supports positive and negative edge weights, detects negative cycles, and allows full path reconstruction.

Features

  • All-pairs shortest path computation
  • Handles negative edge weights (but not negative cycles)
  • Detects negative cycles
  • Supports disconnected components
  • Provides distance and predecessor matrices
  • Reconstructs shortest paths between any two vertices
  • Includes multiple demonstration examples:
    • Simple weighted graph
    • Negative edge weights
    • Negative cycle detection
    • Disconnected components

Complexity

  • Time Complexity: O(V³)
  • Space Complexity: O(V²)

Demonstration

Run demonstrate_floyd_warshall() to execute sample graphs and visualize results.

This implementation enhances the R graph algorithms module with a core dynamic programming algorithm widely used in routing, optimization, and network analysis.

@siriak siriak requested a review from Copilot October 12, 2025 12:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds a new R6-based implementation of the Floyd–Warshall all-pairs shortest paths algorithm, including utilities for path reconstruction, negative-cycle detection, and demonstration examples.

  • Implements core O(V^3) Floyd–Warshall with distance and predecessor matrices
  • Provides path reconstruction and negative cycle detection APIs
  • Includes a demonstration function with multiple example graphs

@siriak siriak requested a review from Copilot October 12, 2025 13:19
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.

@siriak siriak merged commit 69a0c30 into TheAlgorithms:master Oct 12, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants