Graph theory

Posted on January 1, 2013
Tags: algorithms

1 Cuts

Analogous to the partitions of set. In fact, when forming possible cuts, only the elements of the set matter.

\[Cut_A= \{a0,a1,a2,a3\}\] \[Cut_B=\{b0,b1,b2,b3\}\]


2 Undirected Graph

\[\text{Cut-Set(A,B) = Cut-Set(B,A)}\]

\[{\color{red}\text{Cut-Set(A,B)}}=\{e \in edges\ |\ e\ is\ {\color{red}RED}\}\]


3 Directed Graph

\[{\color{red}\text{Cut-Set(A,B)}}=\{e \in edges\ |\ e\ is\ {\color{red}RED}\}\]

\[{\color{purple}\text{Cut-Set(B,A)}}=\{e \in edges\ |\ e\ is\ {\color{purple}PURPLE}\}\]


4 MST

Obviously to Span a tree, one must choose at least 1 edge of a Cut-Set.

The minimum element in a Cut-Set is the edge contained in all MST.

4.1 BFS

4.1.1 Adjacency list


a = [[1,3],[3,4],[2],[5],[],[3]]

b =  [[0 for col in range(0,len(a))] for row in range(0,len(a))]

class Node:
    def __init__(self,data):
        self.children = []
        self.data = data
    def printout(self):
        print(self.data)


def adjToMat(adj,mat):
    for row,adjlist in enumerate(adj):
        for col in adjlist:
           mat[row][col] = 1 
    return mat

c = adjToMat(a,b)

def prettyMat(x):
    colLabel = "  ".join([str(i) for i in range(0,len(x))])
    print(f"   {colLabel}")
    for row,i in enumerate(x):
        print(f"{row} {i}")
prettyMat(c)

#    0  1  2  3  4  5
# 0 [0, 1, 0, 1, 0, 0]
# 1 [0, 0, 0, 1, 1, 0]
# 2 [0, 0, 1, 0, 0, 0]
# 3 [0, 0, 0, 0, 0, 1]
# 4 [0, 0, 0, 0, 0, 0]
# 5 [0, 0, 0, 1, 0, 0]