Skip to content

Updated doc for bfs dfs #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Breadth-first search (BFS)
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.

--------------------
![](https://upload.wikimedia.org/wikipedia/commons/4/46/Animated_BFS.gif)

--------------------
This is the algorithm for Breadth First Search in a given graph.

* We take a starting vertex , and push all its adjacent vertexes in a queue.
* 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.
* After executing the code, we will get the vertex visited in a breadth first manner.

[More info](https://en.wikipedia.org/wiki/Breadth-first_search)

This file was deleted.

13 changes: 13 additions & 0 deletions Competitive Coding/Graphs/Graph_Search/DepthFIrstSearch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Depth-first search (DFS)
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

----
![](https://upload.wikimedia.org/wikipedia/commons/7/7f/Depth-First-Search.gif)
----
This is the algorithm for Depth First Search in a given graph.

* We take a starting vertex , and push all its adjacent vertexes in a stack.
* 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.
* After executing the code, we will get the vertex visited in a depth first manner.

[more info](https://en.wikipedia.org/wiki/Depth-first_search)
17 changes: 17 additions & 0 deletions Competitive Coding/Graphs/Shortest Path/Floyd Warshall/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Floyd–Warshall algorithm
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.

------------------------------
![](https://ds055uzetaobb.cloudfront.net/image_optimizer/bec3c44826d7cab9b828f339e4844b5a09df5fce.png)

### Algorithm

If w(i,j) is the weight of the edge between
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)).
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.

----------------------------
### Performance Analysis
* Worst-case performance O(|V|^3)
* Best-case performance O(|V|^3)
* Average performance O(|V|^3)