Search Knowledge

© 2026 LIBREUNI PROJECT

Mathematics / Set Theory & Structures

Graph Theory

Graph Theory: Structures and Connectivity

Graphs provide a formal framework for modeling relationships between discrete objects.

Fundamental Connectivity

  • Connected Graph: A path exists between every pair of vertices.
  • Components: The maximal connected subgraphs of a non-connected graph.
  • Bipartite Graphs: A graph whose vertices can be divided into two disjoint sets such that every edge connects a vertex in to one in .

Planar Graphs and Euler’s Formula

A graph is planar if it can be drawn in the plane without edges crossing.

  • Euler’s Formula: For any connected planar graph with vertices, edges, and faces:
  • Kuratowski’s Theorem: A graph is planar if and only if it does not contain a subgraph that is a subdivision of (complete graph on 5 nodes) or (complete bipartite graph).

Matchings and Flows

  • Matching: A set of edges without common vertices.
  • Hall’s Marriage Theorem: Provides a necessary and sufficient condition for a bipartite graph to have a perfect matching.
  • Network Flow: Modeling capacity on edges. The Max-Flow Min-Cut Theorem states that the maximum flow through a network is equal to the capacity of the minimum cut.

Graph Colorability

The Chromatic Number is the smallest number of colors needed to color the vertices of such that no two adjacent vertices share a color.

  • The Four Color Theorem: Any planar graph can be colored with no more than four colors.

Code: Finding Cycles (DFS)

def has_cycle(graph, node, visited, recursion_stack):
    visited.add(node)
    recursion_stack.add(node)

    for neighbor in graph[node]:
        if neighbor not in visited:
            if has_cycle(graph, neighbor, visited, recursion_stack):
                return True
        elif neighbor in recursion_stack:
            return True

    recursion_stack.remove(node)
    return False

Directed vs. Undirected

  • Undirected: Edges are like two-way streets.
  • Directed (Digraph): Edges have a direction (e.g., Twitter follows).

Trees

A tree is a connected graph with no cycles. In CS, trees are used for data structures (heaps, BSTs) and decision making.

Representation in Code: Adjacency List

type Graph = Map<number, number[]>;

const graph: Graph = new Map();
graph.set(1, [2, 3]);
graph.set(2, [1, 4]);
graph.set(3, [1]);
graph.set(4, [2]);

// Finding neighbors of node 1
console.log(graph.get(1)); // [2, 3]

Famous Problems

  1. Shortest Path: Dijkstra’s Algorithm.
  2. Traveling Salesperson: Finding the shortest cycle visiting all nodes.
  3. Graph Coloring: Assigning colors such that no two adjacent nodes have the same color.

Exercise

Conceptual Check

What is a tree in graph theory?