Edge

An edge is a connection between two vertices. Usually, it is represented by a line drawn between two vertices. In the previous diagram, we had edges between A and B, A and C, A and D, B and D, C and D, B and E, and D and E. We can represent the edge as AB or (A, B). Edges can be of three types:

  • Directed edge: If an edge is marked with an arrow, then it indicates a directed edge. A directed edge is unidirectional. The head of the arrow is the end vertex and the tail of the arrow is the start vertex:

In the preceding diagram, we can see that A has a directed edge to B, which means A, B is an edge, but not vice versa (B, A). So, this is an example of a unidirectional edge, or directed edge.

  • Undirected edge: An undirected edge is a connection between two vertices without any direction. This means that the edge satisfies a bidirectional relationship. The following diagram is an example of an undirected graph, where A is connected to B in such a way that both edges (A, B) and (B, A) are the same:
  • Weighted edge: When an edge carries additional information, such as cost, distance, or other information, we call that edge a weighted edge. This is used for many graph algorithms. In the following diagram, the weight for edge (A, B) is 5. This can be distance, or cost, or anything, as per the definition of the graph:
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset