#import "@local/dtu-template:0.5.1":*

#show: dtu-note.with(
  course: "01017",
  course-name: "Discrete Mathematics",
  title: "Lecture - November 27, 2025",
  date: datetime(day: 27, month: 11, year: 2025),
  author: "Rasmus Rosendahl-Kaa (S255955)",
  semester: "2025 Fall",
)

= Graphs

== Konigsberg Bridge problem
Consider a river with an island, and where it diverges into two streams. There are 7 bridges to the island.

#image("Lecture-pictures/Konigsberg Bridge Problem.png")

Can you start somewhere and walk over every bridge without walking over a bridge more than once.

*Solution:*\
The layout of the bridges doesn't matter. You can represent the island, and the land areas as points. So 4 points, and lines between them. What you have is a graph. The points are *vertexes* and the lines/curves are *edge* (you can have single-edges, double-edges, and so on). If you have more than 3 vertexes between two vertexes, its called a multiple edge. A loop is an edge looping to the same vertex.

If there are no loops or multiple edges, the graph is called _simple_.

#definition(title: "Vertex")[
A vertex is the points in the graph.

$V(G)={v_1,v_2,dots,v_n}$ are the vertices in graph $G$

An isolated vertex is a singular vertex with no edges.
]

#proof()[
    Assume $G$ is connected and every vertex has even degree. We shall find a closed Euler walk.\
    You start in a vertex $s$ and go to a random neighbor. Continue this until you can't anymore. You _will_ stop in $s$ because else $s$ will always have degree 1.

    This doesn't prove it necessarily because you don't know if some vertex has another edge. Though you can solve this by starting from the vertex that has more edges, and assuming that is a smaller graph, so you complete that.
]

#theorem()[
    A graph $G$ has a closed Euler walk if and only if ($<=>$) every vertex has even degree and $G$ is connected.
]

#definition(title: "Degree")[
    The amount of edges going out of a vertex.
]

#definition(title: "Euler circuit/walk/tour")[
*Closed (circuit):*\
You start in a vertex $s$ and go through every edge precisely once and return in $s$.

*Open (path):*\
The same as closed, but you return to $t$, not $s$
]

#definition(title: "Connected")[
A graph is called connected when there's a path between every vertexes ($forall x,y in V(G)$).\
If not, it is called *disconnected*.

- *Strongly connected:* A directed graph is strongly connected if there is a path from a to b and from b to a whenever a and b are vertices in the graph.
- *Weekly connected:* A directed graph is weakly connected if there is a path between every two vertices in the
underlying undirected graph.
]
#definition(title: "Connected component (piece)")[
For a graph, there is not connected, you can have connected components. Is is a subgraph of the graph that is connected.

You can also call it the maximal connected subgraph
]

== Degree sequence
#definition(title: "Complete")[
A complete graph of _n_ vertices, denoted $K_n$, is a simple graph that contains exactly one edge between each pair of distinct vertices. Like a tetrahedron
#image("Lecture-pictures/Tetrahedron.svg",width: 50%)

A tetrahedron can be realized as a degree sequence ($3,3,3,3$)
]



#definition(title: "Degree Sequence")[
  The *degree sequence* of a graph is a list of the degrees of its vertices, usually written in non-increasing order.

  For example, if a graph has vertices with degrees 3, 2, 2, and 1, its degree sequence is (3, 2, 2, 1).
]

#lemma()[
*Hand shaking Lemma*

For a graph $G$ with vertices $v_1,v_2,dots,v_n$ and degrees\ $deg(v_1),deg(v_2),dots,deg(v_n)$.
$
sum^(n)_(i=1)deg(v_i)=2|E(G)|
$
#proof()[
Each edge is contributing to the total degree twice, so the sum of the degrees are just the twice the amount of edges.
]

Every graph has an even number of odd-degree vertices, because to get an even degree you can't have a single odd degree.
]

#definition(title: "Path")[
The path is a line of vertices. $P_n$
]
#definition(title: "Cycle")[
#image("Lecture-pictures/Cycle.png")

]
#definition(title: "Wheel")[
#image("Lecture-pictures/Wheel.png")
]
#definition(title: "n-cube")[
#image("Lecture-pictures/n-Cube.png")
$Q_n$

$ V(Q_n)={(x_1,x_2,dots, x_(n))| x_(i) in {0,1}} $

Two vertices $(x_1,dots,x_n)$ and $(y_1,dots,y_n)$ are neighbors if and only if $exists ! i : x_i eq.not y_i$
]

#definition(title: "Tree and forest")[
A tree (like a family tree) is also a graph. It is a connected graph without cycle

A forest is a (_non-connected_) graph without cycle
]

#definition(title: "Bipartite")[
A bipartite graph with $"bipartite"(V_1,V_2)$ is a graph with $V(G)=V_1 union V_2$ and all its edges go from $V_1 "to" V_2$

]


== The marriage problem
You have a collection of men (set $V_1$) and a collection of women (set $V_2$). Some man may know some women.

The problem is: Can every man marry a women, when a man can only marry _one_ woman.\
It will not be possible to solve if you have more men than women. Even if you have more women than men, there is a possibility of not all men having married, if, for example, 3 men know some 3 women out of 4, but there is a man who doesn't know any women.

#theorem(title: "Hall's marriage problem")[
A bipartite graph $G$ with bipartitian $V_1,V_2$ has a matching with $|V_1|$ edges if and only if:
$ forall S subset.eq V_1, |N(S)| >= |S| $
which is called Hall's condition.

So if you take 3 men, they should know at least 3 women.

Hall's condition solves the marriage problem because you can take a subset containing one man, which then must be at least 1 (so every man will know at least one woman if Hall's condition is true).
]

#definition(title: "Matching")[
Every vertex has degree at most 1
]

== Isomorphism problem
#definition(title: "Isomorphism problem")[
#image("Lecture-pictures/Isomorphism.jpg",width:40%)
$ G tilde.eq H <=>^("def") V(G)={v_1,v_2,dots,v_n}, V(H)={u_1,u_2,dots,u_n}\
v_i v_j "is an edge" <=> u_i u_j "is an edge"
$
A graph is isomorphism if, for every pair of vertices in one that are neighbors, a likewise pair should be in the other (though they can be arranged in a different way)
]

== Adjacency matrix
#set math.mat(delim: "[")
#definition(title: "Adjacency matrix")[
#image("Lecture-pictures/Adjacency-Matrix.jpg", width: 50%)
A matrix consisting of all the neighbors:

$mat("",v_1,v_2,v_3,v_4;v_1,0,1,0,1;v_2,1,0,1,1;v_3,0,1,0,1;v_4,1,1,1,0)$
]

#definition(title: "Directed graph")[
There is a path through the graph

*Strongly directed:* A graph $D$ is strongly connected if and only f $forall x,y in V(D):$ D contains a directed path from $x$ to $y$ and from $y$ to $x$

*Weekly directed:* If you take all the directed away, you will be left with an undirected graph which is still connected.
]

Strong component: The directed path is also the maximal connected graph.

#definition(title: "Complementary")[
 The complementary graph $overline(G)$ of a simple graph $G$ has the same vertices as $G$. Two vertices are adjacent in $G$ if and only if they are not adjacent in $G$. Describe each of these graphs.

 A simple graph G is called self-complementary if $G$ and $overline(G)$ are isomorphic
]
