diff --git a/Competitive Coding/Graphs/Graph_Search/BreadthFirstSearch/BFS.md b/Competitive Coding/Graphs/Graph_Search/BreadthFirstSearch/BFS.md deleted file mode 100644 index 061e443bc..000000000 --- a/Competitive Coding/Graphs/Graph_Search/BreadthFirstSearch/BFS.md +++ /dev/null @@ -1,5 +0,0 @@ -This is the algortihm 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. diff --git a/Competitive Coding/Graphs/Graph_Search/BreadthFirstSearch/README.md b/Competitive Coding/Graphs/Graph_Search/BreadthFirstSearch/README.md new file mode 100644 index 000000000..541087136 --- /dev/null +++ b/Competitive Coding/Graphs/Graph_Search/BreadthFirstSearch/README.md @@ -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) diff --git a/Competitive Coding/Graphs/Graph_Search/DepthFIrstSearch/DFS.md b/Competitive Coding/Graphs/Graph_Search/DepthFIrstSearch/DFS.md deleted file mode 100644 index 10d3c4f2f..000000000 --- a/Competitive Coding/Graphs/Graph_Search/DepthFIrstSearch/DFS.md +++ /dev/null @@ -1,5 +0,0 @@ -This is the algortihm 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. diff --git a/Competitive Coding/Graphs/Graph_Search/DepthFIrstSearch/README.md b/Competitive Coding/Graphs/Graph_Search/DepthFIrstSearch/README.md new file mode 100644 index 000000000..741ce68d0 --- /dev/null +++ b/Competitive Coding/Graphs/Graph_Search/DepthFIrstSearch/README.md @@ -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) diff --git a/Competitive Coding/Graphs/Shortest Path/Floyd Warshall/README.md b/Competitive Coding/Graphs/Shortest Path/Floyd Warshall/README.md new file mode 100644 index 000000000..349753e1e --- /dev/null +++ b/Competitive Coding/Graphs/Shortest Path/Floyd Warshall/README.md @@ -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)