Graphs & graph algorithms Flashcards
what is complete graph (clique) ?
what is bipartite?
a graph is complete if every pair vertices is joined by an edge.
two sets of disjoint vertices, each vertices is joined with all the vertices on the other set. bipartite is complete
what is connected graph?
what is a tree?
what is a forest?
if every pair of vertices is joined by a path
tree is connected and acyclic
a forest is acyclic and components are trees
directed graph
u->v
in degree and out degree of a vertice
u is adjacent to v and v is adjacent from u
in degree = number of arrow pointing to the vertices
out degree = number of arrow pointing from the vertices
depth first search vs breadth first search
depth first search follows a path of unvisited vertices until path can not be extended the backtrack until an unvisited vertex can be reached. a d e || V b || V c
breadth first search visits all the adjacent vertices first. referring to processing the current vertex. visited nodes are added into the queue. continue until all vertices in the current component have been processed
a=>d=>f
b
c
application of depth first search and its complexity
to determine a connected graph
to identify the connected component of graph
to determine a cycle
to determine a bipartite
complexity O(n+m)
n is number of vertices
m is number of edges
application of breadth first search and its complexity
find the distance between two vertices in a graph
distance is the number of edges in the shortest path
complexity = O(|V| + |E|) v is number of vertices E is number of edges each vertices is visited once and each each adjacent list is traversed once
Dijkstra algorithm
create list of all known nodes and include starting node u with distance of 0
set all unknown nodes shortest distance to infinity
calculate all distances from u to adjacent nodes (0 + distance)
update the shortest distances of the adjacent nodes according to min(current distance, distance of u+distance)
visit the node with the shortest distance and continue the update shortest nodes and visit the shortest distance nodes until the destination is reached
directed acyclic graph
topological order
source and sink
DAG is a directed graph with no cycles
topological order in DAG is a labelling of vertices such that label u < label v
only DAG has topological order
source is a vertex with in degree 0
sink is a vertex with out degree 0
DAG has at least one source and one sink
Spanning tree
a subgraph that includes all vertices of the graph and is a tree
prim jarnik algorithm
find minimum spanning tree
it finds a subset of edges that forms a tree that includes every vertex where the total weight of all the edges is minimized
local optimality -> globally optimal
dijkstra refinement to shortest spanning tree
introduce attribute bestTV for each non tree vertex q which distance between p and q is minimized
complexity O(n^2)