Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Selected Graph Algorithms

License

NotificationsYou must be signed in to change notification settings

srohit0/DataScienceGraphAlgorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This live repo aims to cover basic graph algorithms implemented in C++ (for performance reasons) used in data science. It's meant for educational purposes and will continue to evole.

Introduction

This repo covers basic graph algorithms for directed and undirected graphs with/without weights on edges. Graph description is read from a file with ascii format.

Base graph data structure is targeted forsparse graphs efficiency. For example, it maintains adjancy list and pointrs. Here are big-O time and space complexities.

RAMnode-addedge-addnode-removeedge-removequery
Adjacency List[n]+[e]11[n]+[e][e][e]
Incident List[n]+[e]11[e][e][e]

Legend:

  • Two vertices are called adjacent if they are connected by an edge.
  • Two edges are called incident, if they share a vertex.

Basic Graph

Graph Structure

namespacebasicGraph {...classbNode {private:string                         name_;// node nameset<const bEdge*, edgeCompare> edgelist_;// incident list...}/classbEdge {private:const bNode* n1_;// from node for directd graphsconst bNode* n2_;// to   node for directed graphs...};...classbGraph {private:bool                           isDirected_;set<const bNode*, nodeCompare> nodeset_;set<const bEdge*, edgeCompare> edgeset_;...};}

For more details, refer tograph.h.

Algorithms Covered

Graph File Format

graph (un)directed`<node-x> <node-y> [edge-weight]

Example Graph File

Example Graph

# Comment, ignored by the graph readergraph directedn1 n2 2n1 n3 4n2 n3 1n2 n4 4n2 n5 2n3 n5 3n4 n6 2n5 n4 3n5 n6 2

Application

How to Compile

cd src<c++-compiler> *.cpp -o bgaMain.exe

How to Run

bgaMain.exe <graph-file>

Example run

$ src/bgaMain.exe test/dgraph5.txt

created graph with 6 nodes and 9 edges.type 'help' for more options

help

 help print search  <root_node> sort mst     [prim|kruskal] path    <root_node> quit

print

graph directedn2 n3 1n1 n2 2...

path n1

nd dist_from_src edge== ============= ====n1       0       [none  n1 0]n2       2       [n1  n2 2]n3       3       [n2  n3 1]

Disclaimer

This is a quick and dirty code produced over weekends. Main objective behind this repository is purely educational. It has quite a bit of room for improvement. Feel free to reach out if you spot weakness, bug, enancement or simply a suggestion.


[8]ページ先頭

©2009-2025 Movatter.jp