BCA151 Discrete Structure

Discrete StructureUnit 612 min read

Graph Theory Basics: Definitions, Types, and Representations

Unit 6 of Discrete Structure: Introduces fundamental concepts of graph theory, including definitions of graphs, types of graphs, representations (adjacency matrix and list), and basic properties like connectivity, isomorphism, and degrees.

TAKEAWAYS:

  • A graph is a mathematical structure consisting of vertices (nodes) and edges connecting pairs of vertices, used to model real-world relationships like social networks or transportation routes.
  • Directed graphs (digraphs) and undirected graphs differ in edge orientation, with applications in routing (e.g., Pathao’s ride allocation) and dependency tracking (e.g., course prerequisites).
  • Connectivity determines if a graph is fully traversable, critical for designing efficient networks like NTC’s fiber-optic backbone or Ncell’s mobile towers.
  • Isomorphism checks if two graphs have identical structures, useful in cryptography (e.g., verifying network topologies) and game theory (e.g., puzzle symmetries).
  • Adjacency matrices/lists encode graph data for algorithms, enabling pathfinding (e.g., Google Maps) and social media friend recommendations.
  • Bipartite graphs model pairwise relationships (e.g., Daraz’s order-fulfillment queues), while trees optimize hierarchical data (e.g., file systems in computers).

1. Introduction to Graphs

A graph is a pair , where:

  • is a finite set of vertices (or nodes).
  • is a set of edges, which are 2-element subsets of (for undirected graphs) or ordered pairs (for directed graphs).
ABCD
Directed cycle graph (4-cycle) showing a closed loop: A→B→C→D→A. Used in circular dependencies (e.g., course prerequisites).
v1v2v3v4
Undirected graph with vertices {v1, v2, v3, v4} and edges {v1–v2, v1–v3, v2–v3, v2–v4, v3–v4}. Degree(v1)=2, Degree(v2)=3, etc.

Types of Graphs

Type Definition Example in Real World
Undirected Graph Edges have no direction; represents an unordered pair. NTC’s fiber-optic network (bidirectional links).
Directed Graph Edges have direction; implies a one-way connection. Pathao’s ride allocation (driver → passenger).
Weighted Graph Edges have weights (e.g., distances, costs). Google Maps (road distances between cities).
Simple Graph No loops (edges from a vertex to itself) and no multiple edges between vertices. Social media friendships (no repeated connections).
Multigraph Allows multiple edges between the same pair of vertices. Parallel phone lines between two towers.
Pseudograph Allows loops and multiple edges. Traffic flow with roundabouts (loops).

A -- B
| \ |
|  \|
C --
1 → 2 → 3
 \      /
   \    /
     1

Key Definitions

  • Degree of a Vertex: Number of edges incident to it.
    • In undirected graphs: number of edges connected to .
    • In directed graphs:
      • In-degree: Number of edges entering .
      • Out-degree: Number of edges leaving .
  • Path: A sequence of edges connecting a sequence of vertices (e.g., ).
  • Cycle: A path that starts and ends at the same vertex with no repeated edges/vertices (except the start/end).
  • Connected Graph: There is a path between every pair of vertices.
  • Complete Graph: Every pair of distinct vertices is connected by a unique edge (denoted for vertices).

Worked Example: Degrees and Edges Given an undirected graph with vertices and adjacency matrix:

0 1 1 0
1 0 1 1
1 1 0 1
0 1 1 0

Find:

  1. The degree of each vertex.
  2. The total number of edges.

Solution:

  1. Degrees are the row/column sums (excluding diagonal zeros):
    • (edges to ),
    • (edges to ),
    • ,
    • .
  2. Total edges = .

2. Representations of Graphs

Graphs can be represented using:

  1. Adjacency Matrix: A square matrix where if , else .
    • Useful for dense graphs (many edges).
    • Example for the graph above:
      [[0,1,1,0],
       [1,0,1,1],
       [1,1,0,1],
       [0,1,1,0]]
      
  2. Adjacency List: A list of lists where each vertex points to its neighbors.
    • Example:
      v1: v2, v3
      v2: v1, v3, v4
      v3: v1, v2, v4
      v4: v2, v3
      
    • Space-efficient for sparse graphs.

Comparison Table: Adjacency Matrix vs. List

Feature Adjacency Matrix Adjacency List
Space Complexity (always fills matrix) (only stores existing edges)
Edge Lookup (direct access)
Best For Dense graphs Sparse graphs
Example Use NEPSE’s stock market correlations (many trades) Daraz’s order fulfillment (fewer connections)

3. Special Graphs

123456
Binary tree with root 1, left subtree rooted at 2 (children 4,5), right subtree rooted at 3 (child 6). Used in file systems (e.g., Windows Explorer).
ABCDE
Bipartite graph with U={A,B} and V={C,D,E}. No odd cycles (e.g., A–C–B–E–D–A is invalid).

Bipartite Graphs

  • A graph whose vertices can be divided into two disjoint sets and such that every edge connects a vertex in to one in .
  • Example:
    U: [A, B]
    V: [1, 2, 3]
    Edges: A-1, A-2, B-2, B-3
    
  • Property: No odd-length cycles (e.g., 3-cycle is invalid).
  • Proof that odd cycles imply non-bipartiteness: Assume a bipartite graph has an odd cycle. Alternate colors (say, red/blue) vertices. The cycle must end on the same color as it started, but odd-length cycles require alternating colors to mismatch. Contradiction.

A -- 1
| \  |
|  \ |
B -- 2 -- 3

Trees

  • A connected acyclic graph.
  • Properties:
    • Exactly edges for vertices.
    • No cycles; exactly one path between any two vertices.
  • Applications:
    • File systems (directories as nodes, subdirectories as children).
    • Organizational hierarchies (e.g., company reporting structures).

      A
     / \
    B   C
   /
  D

Graph Isomorphism

  • Two graphs and are isomorphic if there exists a bijection such that iff .
  • Example: Let and be graphs with:
    • , .
    • , .
    • Isomorphism: . Both are 4-cycles, so they are isomorphic.
abcd
Graph G with vertices {a,b,c,d} forming a 4-cycle. Isomorphic to the example in the note (relabel vertices as 1→a, 2→b, etc.).
G1G2G3G4H1H2H3H4
Isomorphism mapping: G ↔ H with vertex correspondence (4-cycle example)

Mermaid Diagram: Graph Isomorphism Check

graph TD
    subgraph G["Graph G"]
        A["a"] --> B["b"]
        B --> C["c"]
        C --> D["d"]
        D --> A
    end
    subgraph H["Graph H"]
        1["1"] --> 2["2"]
        2 --> 3["3"]
        3 --> 4["4"]
        4 --> 1
    end
    G -->|"f(a)=1, f(b)=2, f(c)=3, f(d)=4"| H

4. Directed Graphs

  • Source Vertex: A vertex with out-degree and in-degree .
  • Sink Vertex: A vertex with in-degree and out-degree .
  • Applications:
    • Pathao: Drivers (sources) allocate rides to passengers (sinks).
    • Course Prerequisites: Math 101 (source) → Math 102 (sink).

S → A → B → T

5. Connectedness

  • Connected Graph: There is a path between every pair of vertices.
  • Disconnected Graph: At least one pair of vertices has no path.
  • Applications:
    • NTC’s Network: If two towers are not connected, calls drop (disconnected).
    • Social Networks: If two users have no mutual friends, they are disconnected.

Mermaid Diagram: Connected vs. Disconnected Graphs

ABCDEFG
Connected (left) vs. disconnected (right) graphs: NTC network (left) and social network (right)

In the Real World

  1. Pathao’s Ride Allocation:

    • Idea: Directed graph where drivers (sources) allocate rides to passengers (sinks).
    • How: The app models supply (drivers) and demand (passengers) as a flow network, optimizing routes using shortest-path algorithms (e.g., Dijkstra’s) on weighted graphs.
  2. Daraz’s Order Fulfillment:

    • Idea: Bipartite graph where one set is orders and the other is warehouses.
    • How: Orders are matched to the nearest warehouse (edges represent delivery routes), ensuring minimal transit time. Bipartite graphs help avoid conflicts where a single warehouse cannot fulfill multiple orders simultaneously.
  3. NEPSE’s Stock Market Correlations:

    • Idea: Weighted graph where vertices are stocks and edges are correlation coefficients.
    • How: Traders use adjacency matrices to identify high-correlation stocks (e.g., Ncell and NTC shares often move together) for portfolio diversification or risk assessment.

Worked Example: Graph Isomorphism

Question: Determine if the following two graphs are isomorphic.

  • : Vertices , edges .
  • : Vertices , edges .

Solution:

  1. Check Degrees:
    • : .
    • : . Degrees match, so isomorphism is possible.
  2. Construct Bijection:
    • Map , , , .
    • Verify edges: , , .
    • Conclusion: and are isomorphic (both are "path graphs" of length 3).

Exam Tip

  1. Definitions: Always recall definitions precisely (e.g., "a bipartite graph has no odd cycles"). Partial credit is lost for vague answers like "a graph with two parts."
  2. Visualization: Draw graphs for isomorphism proofs. Even if the question doesn’t ask, sketching helps you see patterns (e.g., cycles, trees).
  3. Adjacency Matrix/Lists: Practice converting between the two representations quickly. For example, given a matrix, list the edges; given a list, construct the matrix.
  4. Proofs: For statements like "a graph with an odd cycle is not bipartite," use contradiction or coloring arguments. Show your steps clearly.
  5. Real-World Tie-Ins: Relate graph concepts to apps you use daily (e.g., "Why is Pathao’s ride system a directed graph?").
  6. Time Management: Spend 10 minutes per question. For isomorphism, start by checking degrees before attempting bijections.

Based on the TU BCA syllabus for Discrete Structure (BCA151), unit 6.

Discussion

Loading…