graph and trees
graph and trees
One room
One edge for each parent child relationship
Special type of tree
Graph
Nodes and edges, no rules
Ordered pair
(A,B) != (B,A)
Unordered pair
{a,b} = {b,a}
Social Network is undirected graph (2 way, if I am your friend, you are mine)
Web pages having link of another pages is directed graph (A -> B -> C)
Web crawling is graph traversal (traversing all nodes on www)
Weighted vs unweighted
Self loop — eg web page - which can link to itself — multi tab in page
Multi edge - if it occurs more than one time
A graph is called dense , if too many edges are there - almost square to number of
vertices
Sparse - less edges — close to vertices
Strongly connected graph - path from any vertex to any other vertex — only for directed
graph,
For undirected we call it connected graph if there is a path from any vertex to any other
vertex (A- B - C- D- E)
For a directed graph , it matters - start index, endVertext, for undirected just add one
record for single path.
If |V| = n
Then 0 <= |E| <= n(n-1) for directed
0 <= |E| < = (n(n-1)/2);
For dense, it’s fine, but for sparse , it will waste space