Skip to content

Commit

Permalink
Update graph_algorithms.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Ankitha2130 authored Oct 5, 2024
1 parent a1ad71e commit e298df1
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions docs/graphs/graph_algorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The algorithm starts from a given source and explores all reachable vertices fro

Implementation in Java:

Input parameters- 1) ArrayList<ArrayList<Integer>> adj - Adjacency list representation of the graph.
Input parameters- 1) adj - Adjacency list representation of the graph.
2) s - source node
```java
public void bfsOfGraph(ArrayList<ArrayList<Integer>> adj, int s) {
Expand Down Expand Up @@ -59,7 +59,7 @@ Steps for DFS of a Graph :

Implementation in Java:

Input parameters- 1) ArrayList<ArrayList<Integer>> adj - Adjacency list representation of the graph.
Input parameters- 1) adj - Adjacency list representation of the graph.
2) s - source node
3) Boolean array named 'visited'
```java
Expand Down Expand Up @@ -104,7 +104,7 @@ Steps for Topological Sorting :

Implementation in Java:

Input parameters- 1) ArrayList<ArrayList<Integer>> adj - Adjacency list representation of the graph.
Input parameters- 1) adj - Adjacency list representation of the graph.
2) V - number of vertices.

```java
Expand Down Expand Up @@ -179,7 +179,7 @@ Steps for Prim's Algorithm :

Implementation in Java:

Input parameters- 1) ArrayList<ArrayList<Integer>> adj - Adjacency list representation of the graph.
Input parameters- 1) adj - Adjacency list representation of the graph.
2) s - source node

```java
Expand Down Expand Up @@ -302,7 +302,7 @@ Steps for Dijkstra's Algorithm :

Implementation in Java:

Input parameters- 1) ArrayList<ArrayList<Integer>> adj - Adjacency list representation of the graph.
Input parameters- 1) adj - Adjacency list representation of the graph.
2) s - source node

```java
Expand Down Expand Up @@ -768,8 +768,8 @@ Output: Shortest distance to all vertices from src. If there is a negative weigh

1) This step initializes distances from source to all vertices as infinite and distance to source itself as 0. Create an array dist[] of size |V| with all values as infinite except dist[src] where src is source vertex.
2) This step calculates shortest distances. Do following |V|-1 times where |V| is the number of vertices in given graph. Do following for each edge u-v:
i) If dist[v] > dist[u] + weight of edge uv, then update dist[v] as: dist[v] = dist[u] + weight of edge uv.
3) This step reports if there is a negative weight cycle in graph. Do following for each edge u-v. If dist[v] > dist[u] + weight of edge uv, then "Graph contains negative weight cycle".
i) If dist[v] greater than dist[u] + weight of edge uv, then update dist[v] as: dist[v] = dist[u] + weight of edge uv.
3) This step reports if there is a negative weight cycle in graph. Do following for each edge u-v. If dist[v] greater than dist[u] + weight of edge uv, then "Graph contains negative weight cycle".

Implementation on Java :
```java
Expand Down

0 comments on commit e298df1

Please sign in to comment.