Skip to content

Commit 860188c

Browse files
authored
Merge pull request #218 from imVivekGupta/sort_doc
Updated doc for bfs dfs
2 parents 6419593 + 4cfa461 commit 860188c

File tree

5 files changed

+44
-10
lines changed

5 files changed

+44
-10
lines changed

Competitive Coding/Graphs/Graph_Search/BreadthFirstSearch/BFS.md

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Breadth-first search (BFS)
2+
An algorithm for traversing or searching tree or graph data structures. It starts at the tree root (or some arbitrary node of a graph, sometimes referred to as a 'search key') and explores the neighbor nodes first, before moving to the next level neighbours.
3+
4+
--------------------
5+
![](https://upload.wikimedia.org/wikipedia/commons/4/46/Animated_BFS.gif)
6+
7+
--------------------
8+
This is the algorithm for Breadth First Search in a given graph.
9+
10+
* We take a starting vertex , and push all its adjacent vertexes in a queue.
11+
* Now we pop an element from a queue and push all its vertexes in the queue , and we also mark down these vertexes as visited.
12+
* After executing the code, we will get the vertex visited in a breadth first manner.
13+
14+
[More info](https://en.wikipedia.org/wiki/Breadth-first_search)

Competitive Coding/Graphs/Graph_Search/DepthFIrstSearch/DFS.md

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Depth-first search (DFS)
2+
An algorithm for traversing or searching tree or graph data structures. One starts at the root (selecting some arbitrary node as the root in the case of a graph) and explores as far as possible along each branch before backtracking
3+
4+
----
5+
![](https://upload.wikimedia.org/wikipedia/commons/7/7f/Depth-First-Search.gif)
6+
----
7+
This is the algorithm for Depth First Search in a given graph.
8+
9+
* We take a starting vertex , and push all its adjacent vertexes in a stack.
10+
* Now we pop an element from a stack and push all its vertexes in the stack , and we also mark down these vertexes as visited.
11+
* After executing the code, we will get the vertex visited in a depth first manner.
12+
13+
[more info](https://en.wikipedia.org/wiki/Depth-first_search)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Floyd–Warshall algorithm
2+
An algorithm for finding shortest paths in a weighted graph with positive or negative edge weights (but with no negative cycles). A single execution of the algorithm will find the lengths (summed weights) of the shortest paths between all pairs of vertices.
3+
4+
------------------------------
5+
![](https://ds055uzetaobb.cloudfront.net/image_optimizer/bec3c44826d7cab9b828f339e4844b5a09df5fce.png)
6+
7+
### Algorithm
8+
9+
If w(i,j) is the weight of the edge between
10+
vertices i and j, we can define shortestPath (i,j,k) in terms of the following recursive formula: the base case is shortestPath (i,j,0)=w(i,j) and the recursive case is shortestPath (i,j,k) = min( shortestPath (i,j,k-1), shortestPath (i,k,k-1)+ shortestPath (k,j,k-1)).
11+
This formula is the heart of the Floyd–Warshall algorithm. The algorithm works by first computing shortestPath (i,j,k) for all (i,j) pairs for k=1, then k=2, etc. This process continues until k=N, and we have found the shortest path for all (i,j) pairs using any intermediate vertices.
12+
13+
----------------------------
14+
### Performance Analysis
15+
* Worst-case performance O(|V|^3)
16+
* Best-case performance O(|V|^3)
17+
* Average performance O(|V|^3)

0 commit comments

Comments
 (0)