Graph in the simplest terms is a representation of some real world fact in terms of nodes and edges. It consists of a collection of nodes and a set of edges connecting them. In a general graph, there is no restriction on type of nodes that can be connected by an edge.
Tree on the other hand are special case of graph where there exists exactly one path between each pair of nodes. A tree is just connected. Adding even a single edge results in a cycle. So a tree with n nodes has n-1 edges.
Traversal
When graph represent some real world entity and we want to examine all the nodes which are connected to each other then its called traversing a graph. Since a general graph can contain a cycle, hence algorithms do exists to avoid such issues. In this blog i will be covering about most recognized graph traversal algorithms. Many of these algorithms are also related to tree traversal. We will be discussing about following graph traversal algorithms
1. Breadth First Search (BFS)
2. Depth First Search (DFS)
3. Prim' Algorithm
4. Kruskal's Algorithm
5. Dijkstra's Algorithm (Single Source Shortest Path )
6. Bellman Ford Algorithm ( Single Source Shortest Path )
7. Floyd Warshall Algorithm (All Pair Shortest Path )
Some of coomon terminology used are
SSSP i.e. Single source shortest path in which we try to find optimum traversal strategy so that all the nodes are at a shortest distance from a particular node.
All Pair is the generalized form of SSSP algorithm. In this, we try to find shortest path between all pair of vertices. i.e. overall distance is minimum.
----------------------------------------------------------------------------------------------
1. Breath First Search
2. Depth First Search
3. Prim's Algorithm
It finds spanning tree in only one of connected graph.
4. Kruskal's Algorithm
If the graph consist of multiple disjoint connected graph then it finds minimum spanning tree in each of graph at once.
5. Dijkstra's Algorithm
SSSP where each node has non negative weight
6. Bellman Ford Algorithm
SSSP where nodes can have negative weight but any cycle with negative value should not exist.
It is interesting to know that a similar problem i.e. graph where negative weight cycle exists, and shortest path finding such that no edge appears twice is NP complete problem
7. Floyd Warshall's Algorithm
Tree on the other hand are special case of graph where there exists exactly one path between each pair of nodes. A tree is just connected. Adding even a single edge results in a cycle. So a tree with n nodes has n-1 edges.
Traversal
When graph represent some real world entity and we want to examine all the nodes which are connected to each other then its called traversing a graph. Since a general graph can contain a cycle, hence algorithms do exists to avoid such issues. In this blog i will be covering about most recognized graph traversal algorithms. Many of these algorithms are also related to tree traversal. We will be discussing about following graph traversal algorithms
1. Breadth First Search (BFS)
2. Depth First Search (DFS)
3. Prim' Algorithm
4. Kruskal's Algorithm
5. Dijkstra's Algorithm (Single Source Shortest Path )
6. Bellman Ford Algorithm ( Single Source Shortest Path )
7. Floyd Warshall Algorithm (All Pair Shortest Path )
Some of coomon terminology used are
SSSP i.e. Single source shortest path in which we try to find optimum traversal strategy so that all the nodes are at a shortest distance from a particular node.
All Pair is the generalized form of SSSP algorithm. In this, we try to find shortest path between all pair of vertices. i.e. overall distance is minimum.
----------------------------------------------------------------------------------------------
1. Breath First Search
2. Depth First Search
3. Prim's Algorithm
It finds spanning tree in only one of connected graph.
4. Kruskal's Algorithm
If the graph consist of multiple disjoint connected graph then it finds minimum spanning tree in each of graph at once.
5. Dijkstra's Algorithm
SSSP where each node has non negative weight
6. Bellman Ford Algorithm
SSSP where nodes can have negative weight but any cycle with negative value should not exist.
It is interesting to know that a similar problem i.e. graph where negative weight cycle exists, and shortest path finding such that no edge appears twice is NP complete problem
7. Floyd Warshall's Algorithm