vertices/nodes connected by edgesvertex - also called node, item with 0 or more adjacent verticesedge - connection between two nodesneighbor - adjacent nodes connected via an edgedegree - number of edges connected to vertexundirected graph each edge is undirected or bi-directional
directed graphs or digraph every edge is directed
complete graph all nodes touch all other nodesconnected each node has at least 1 edgedisconnected some vertices have no edge, or there are isolated areasacyclic is directed graph without cycles
cycle is a loop back to the origin nodedirected acyclic graph or DAG…aka treecyclic graph has loopsa b c d e f a0 0 1 1 0 0 b0 0 1 0 0 1 c1 1 0 0 1 0 d1 0 0 0 1 0 e0 0 1 1 0 1 f0 1 0 0 1 0
sparse is few connectionsdense is many connectionssymmetric, not so for directeda>c>d b>c>f c>a>b>e d>a>e e>c>d>f f>b>e
a b c d a0 4 3 9 b4 0 0 5 c3 0 0 6 d9 5 6 0
a>b,4>d,9>c,3 b>a,4>d,5 c>a,3>d,6 d>a,9>b,5>c,6
flag to prevent infinite loopsenqueue the start nodedequeue the first node from queuedequeued node has unvisited child nodes, mark them as visited and insert in to the queue
ALGORITHM BreadthFirst(vertex)
DECLARE nodes <-- new List()
DECLARE breadth <-- new Queue()
breadth.Enqueue(vertex)
while (breadth is not empty)
DECLARE front <-- breadth.Dequeue()
nodes.Add(front)
for each child in front.Children
if(child is not visited)
child.Visited <-- true
breadth.Enqueue(child)
return nodes;