Skip to content

C++ project implementing a dynamic, undirected weighted graph with an interactive menu-driven interface. Supports adding and removing vertices and edges, printing the graph, and computing shortest paths using Dijkstra’s algorithm (O(V²) scan, without STL priority queues).

License

therealdaud/cpp-dynamic-graph-dijkstra

Repository files navigation

C++ Dynamic Graph with Dijkstra’s Shortest Path

Menu-driven dynamic, undirected weighted graph in C++: add/remove vertices and edges at runtime and compute shortest paths using Dijkstra’s algorithm (implemented with a linear scan, i.e., O(V²); no STL priority queue).


✨ Features

  • Adjacency list graph with labeled vertices and weighted edges.
  • Add/remove vertices and edges with input validation (no self-loops, no duplicate edges).
  • Dijkstra’s algorithm via manual min-selection (clarity over speed), plus path reconstruction.
  • Simple CLI menu for interactive updates and queries.
  • Clean separation of interface and implementation (GraphBase, Graph, main).

📂 Project Structure

├── GraphBase.hpp # Abstract graph interface (add/remove/query APIs) GraphBase

├── Graph.hpp # Concrete graph (adjacency list, helpers, Dijkstra)

├── Graph.cpp # Implementation of graph ops + O(V²) Dijkstra

├── main.cpp # Menu-driven CLI (add/remove/shortest path/print)

├── COP_4530_Project_Report_.pdf # Design & results write-up

└── COP4530 Presentation.pdf # Slide deck overview


🚀 Build & Run

Compile (C++17+)

g++ -std=c++17 -Wall main.cpp Graph.cpp -o graph

Run

./graph
You’ll see a menu to add/remove vertices/edges, compute shortest paths, and print the graph. 
main

🧠 Algorithm Notes

  • Dijkstra is implemented with a linear scan to pick the next vertex (no STL priority queue), making it O(V² + E) and ideal for small/teaching graphs.

  • Path is reconstructed by walking back using a prev vector.


🛠️ Example Operations

Add Vertex → creates a labeled node if it doesn’t exist.

Add Edge → adds an undirected weighted link (both directions).

Compute Shortest Path → prints path and total cost or “no path”.


✍️ Author

Daud Ahmad Nisar

Computer Science Student at the University of South Florida

daudnisar1@gmail.com

About

C++ project implementing a dynamic, undirected weighted graph with an interactive menu-driven interface. Supports adding and removing vertices and edges, printing the graph, and computing shortest paths using Dijkstra’s algorithm (O(V²) scan, without STL priority queues).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages