Graphs are used to represent connected objects, such as routers in a network or people on a social media platform.
They consist of nodes and edges, where a node is also called a vertex.
Tree vs Graph: A tree is a kind of graph without any cycles, and it has a root node. In contrast, a graph can have cycles and does not have a root node.
Nodes and Edges: Nodes are connected by edges, which represent relationships or connections between the nodes. Nodes can have any number of connections or edges.
Adjacency: Nodes that are directly connected by an edge are called adjacent or neighbours. For example, John and Bob are adjacent in a graph.
Directed vs Undirected Graphs: In a directed graph, edges have a direction, indicating a one-way relationship. In an undirected graph, edges have no direction, representing mutual relationships.
Directed Graph
Undirected Graph