Skip to content

feat: add Dijkstra's Algorithm using Adjacency Matrix#3201

Open
binarymind-dev wants to merge 1 commit into
TheAlgorithms:masterfrom
binarymind-dev:patch-2
Open

feat: add Dijkstra's Algorithm using Adjacency Matrix#3201
binarymind-dev wants to merge 1 commit into
TheAlgorithms:masterfrom
binarymind-dev:patch-2

Conversation

@binarymind-dev

Copy link
Copy Markdown

Description

This PR adds an implementation of Dijkstra's Shortest Path Algorithm
using an Adjacency Matrix representation, without a priority queue.

Changes

  • Added graph/dijkstra_adjacency_matrix.cpp
  • Computes shortest distances from a single source to all vertices in O(V^2)
  • Handles disconnected graphs (unreachable vertices marked with INT_MAX)
  • Includes self-test with assert statements

Difference from existing implementations

  • dijkstra.cpp uses an adjacency list + priority queue (better for sparse graphs)
  • bidirectional_dijkstra.cpp runs a bidirectional search from both source and target
  • This implementation uses an adjacency matrix + linear scan (simpler, better
    for dense graphs, no heap overhead)

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.

1 participant