Graph



An Unweighted Directed Graph


Definition: A data structure consisting of nodes (data - see blue dots above) connected by edges (links - see grey arrows above), representing relationships or connections between elements. There are 2 main characteristics of every graph:

  1. Weight: A graph can be categorized as either weighted or unweighted. In a weighted graph, each edge (link) is assigned a numerical value, such as distance or priority, representing a scalar unit between nodes of data. On the other hand, an unweighted graph has no assigned weights for its edges.

  2. Direction: A graph is either directed, meaning that every edge points towards a node (think an arrow), or undirected, meaning that edges don't have direction (think a straight line rather than an arrow).



Real Life Example: Think of graphs as street maps, where the locations are nodes and the streets are edges. The locations can only be accessed via the correct streets!



Basic Graph Operations:

  1. Adding an edge and/or node. Here, node G is added to the graph and connected to node F via an added edge.
  2. Removing an edge. Since node G has no edges connected to it after this removal, it is considered isolated. This means that it cannot be accessed until it is reconnected via adding a new edge.
  3. Removing a node. Notice that any edges connected to/pointing towards the removed node are removed as well.

Fun Fact: Given all of the different connections in most graphs, they can be very difficult to display. One of the most common solutions to this issue is implementing an adjacency matrix:



Commonly Used In: