From 4e41ed60c7a0eb6acfa71dc0f5f3440334889f1a Mon Sep 17 00:00:00 2001 From: Taranpreet Singh <47025523+taran-1407@users.noreply.github.com> Date: Fri, 2 Oct 2020 02:28:47 +0530 Subject: [PATCH] Added README.md --- GraphBuilder/README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 GraphBuilder/README.md diff --git a/GraphBuilder/README.md b/GraphBuilder/README.md new file mode 100644 index 0000000..22fa59c --- /dev/null +++ b/GraphBuilder/README.md @@ -0,0 +1,40 @@ +# Class GraphBuilder + +Creates graph in form of jagged arrays (as compared to Arraylist) for directed as well as undirected graphs from given set of edges in 0 indexing. + +All members of this class are static, so no constructor defined. + +## Methods + +### makeGraph +``` +public static int[][] makeGraph(int NumberOfNodes, int NumberOfEdges, int[] from, int[] to, boolean undirected) +``` +Returns the adjacency list representation of graph with specified Number of Nodes and Edges and the edges specified in from and to arrays in 0-based indexing. If undirected is set to true, the edges are deemed to be undirected, otherwise directed. + +```graph[u]``` is the array of vertices having an edge outgoing from vertex u. + +** Constraints ** +* 0 \leq from[i], to[i] < NumberOfNodes +* from.length = to.length = NumberOfEdges + +** Computational complexity ** +* $ O (NumberOfNodes + NumberOfEdges) $ + +### makeGraphWithEdgeInfo +``` +public static int[][][] makeGraphWithEdgeInfo(int NumberOfNodes, int NumberOfEdges, int[] from, int[] to, boolean undirected) +``` + +Returns the adjacency list representation of graph with specified Number of Nodes and Edges and the edges specified in from and to arrays in 0-based indexing. If undirected is set to true, the edges are deemed to be undirected, otherwise directed. This method also returns useful information about edge index and edge direction. + +```graph[u]``` is the array of tuples ```[v, idx, direction]``` where edge indexed ```idx``` is between node ```u``` and node ```v``` and direction takes value either $0$ or $1$. +- If direction is $0$, edge indexed ```idx``` is from ```u``` to ```v``` +- If direction is $1$, edge indexed ```idx``` is from ```v``` to ```u``` + +** Constraints ** +* 0 \leq from[i], to[i] < NumberOfNodes +* from.length = to.length = NumberOfEdges + +** Computational complexity ** +* $ O (NumberOfNodes + NumberOfEdges) $