1. Intro to graphs #
Created Monday 30 March 2020
Graph is a data structure that is used to solve a lot of real world problems like:
- Social media network.
- Places connected via roads in a country.
Defintion of a graph #
A set of vertices and a set of edges(connecting them - does not mean all vertex have to be connected).
Tree vs Graph vs DAG #
Graph #
Graphs can:
- Have cycles.
- Can have disjoint sets of graphs. i.e some vertex may be unreachable from all other vertex. e.g 2 friends who are not friends with another group. The graph is actually a set of two disjoint graphs.
Tree #
A tree is a graph with 3 restrictions. A graph is a tree if it is:
- Acyclic
- Connected
- Undirected
Note: Assigning root of a tree is customary.
DAG(Directed Acyclic Graph) #
DAG(directed acyclic graph) is a directed graph with no directed cycles.
- A DAG’s underlying undirected graph may be a tree, but it’s not necessary.
- A directed graph is a DAG if and only if it can be topologically ordered - i.e. for every edge from
p
andq
,p
must occur beforeq
in the ordered seqeuence.