ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Discrete Mathematics
    MATH2113
    Progress0 / 25 topics
    Topics
    1. Mathematical Reasoning: Sets, Subsets, Algebra of Sets2. Propositions and Compound Statements3. Basic Logical Operations4. Propositional Logic and its Applications with Statement Problems5. Propositions and Truth Tables6. Tautologies and Contradictions7. Conditional and Bi-conditional Statements8. Arguments in Propositional Logic9. Propositional Functions10. Quantifiers and Negation of Quantified Statements11. Relations and Equivalence Relations12. Partial Ordering Relations13. Functions and Recursively Defined Functions14. Combinatorics: Basics of Counting Methods15. Combinations and Permutations16. Pigeonhole Principle17. Graphs and its Types18. Graph Isomorphism19. Trees in Graph Theory20. Connectivity in Graphs21. Eulerian and Hamiltonian Paths22. Spanning Trees and Shortest Path Problem23. Revisiting Special Functions: Power, Floor, Increasing, Decreasing24. Big O, Little O and Omega Notations25. Orders of the Polynomial Functions
    MATH2113›Spanning Trees and Shortest Path Problem
    Discrete MathematicsTopic 22 of 25

    Spanning Trees and Shortest Path Problem

    9 minread
    1,506words
    Intermediatelevel

    Spanning Trees and Shortest Path Problem


    In graph theory, spanning trees and the shortest path problem are fundamental concepts with wide-ranging applications in fields such as computer networks, transportation, and optimization. These concepts are used for tasks like minimizing distances, optimizing network connectivity, and routing.


    1. Spanning Trees

    A spanning tree of a graph is a subgraph that includes all the vertices of the original graph, is connected, and has no cycles. Essentially, a spanning tree connects all the vertices of the graph with the minimum number of edges required. If the graph is connected and has VVV vertices, a spanning tree will have exactly V−1V - 1V−1 edges.

    a) Properties of Spanning Trees

    1. Connected and Acyclic: A spanning tree is a connected, acyclic subgraph of the original graph. It contains all the vertices but only a subset of the edges.

    2. Number of Edges: A spanning tree of a graph with VVV vertices will have V−1V - 1V−1 edges.

    3. Uniqueness: A graph can have multiple spanning trees, but each spanning tree will always contain exactly V−1V - 1V−1 edges and will cover all VVV vertices.

    4. Minimal Connectivity: A spanning tree provides the minimal set of edges required to maintain connectivity between all the vertices.

    b) Types of Spanning Trees

    1. Minimum Spanning Tree (MST): A minimum spanning tree is a spanning tree where the total weight of the edges is minimized. In weighted graphs, the MST ensures the least cost to connect all vertices.

    2. Maximum Spanning Tree: A maximum spanning tree is similar to the MST but maximizes the total weight of the edges rather than minimizing it.

    c) Algorithms to Find Spanning Trees

    There are two well-known algorithms to find a minimum spanning tree in a weighted, connected graph:

    1. Kruskal’s Algorithm:

      • This algorithm adds edges to the spanning tree in increasing order of their weights, ensuring that no cycles are formed.
      • It uses a disjoint-set data structure (also known as union-find) to track connected components.
      • Time complexity: O(Elog⁡E)O(E \log E)O(ElogE), where EEE is the number of edges.
    2. Prim’s Algorithm:

      • This algorithm starts with an arbitrary vertex and grows the MST by adding the smallest weight edge connecting a vertex inside the tree to a vertex outside the tree.
      • It uses a priority queue to always expand the tree by the minimum edge.
      • Time complexity: O(Elog⁡V)O(E \log V)O(ElogV) using a binary heap, where VVV is the number of vertices.

    d) Applications of Spanning Trees

    1. Network Design: Spanning trees are used in the design of computer networks to minimize the cost of connecting all the nodes (e.g., laying out communication cables).

    2. Broadcasting: In wireless networks, spanning trees can help in efficiently broadcasting data to all nodes while minimizing interference.

    3. Circuit Design: Spanning trees help in minimizing the number of connections needed to wire up a set of components in circuit design.


    2. Shortest Path Problem

    The shortest path problem involves finding the shortest path between two vertices in a graph, considering either the edge weights (in a weighted graph) or the number of edges (in an unweighted graph). There are several variations of the shortest path problem, including single-source shortest path, single-pair shortest path, and all-pairs shortest path problems.

    a) Types of Shortest Path Problems

    1. Single-Source Shortest Path: This involves finding the shortest path from a single source vertex to all other vertices in the graph.

    2. Single-Pair Shortest Path: This involves finding the shortest path between two specific vertices in the graph.

    3. All-Pairs Shortest Path: This involves finding the shortest path between every pair of vertices in the graph. This is generally solved using the Floyd-Warshall algorithm.

    b) Algorithms for Shortest Path

    There are several algorithms for solving the shortest path problem, depending on the type of graph (weighted, unweighted, directed, or undirected).

    1. Dijkstra’s Algorithm (Single-Source, Weighted Graphs):

      • Dijkstra's algorithm is used to find the shortest path from a source vertex to all other vertices in a graph with non-negative edge weights.
      • It works by progressively selecting the closest unvisited vertex and updating the tentative distances to its neighbors.
      • Time complexity: O(Elog⁡V)O(E \log V)O(ElogV) using a priority queue, where EEE is the number of edges and VVV is the number of vertices.
    2. Bellman-Ford Algorithm (Single-Source, Weighted Graphs):

      • The Bellman-Ford algorithm is used for graphs that may contain negative edge weights. It works by relaxing all the edges repeatedly.
      • It can also detect negative-weight cycles in the graph.
      • Time complexity: O(V⋅E)O(V \cdot E)O(V⋅E), where VVV is the number of vertices and EEE is the number of edges.
    3. Floyd-Warshall Algorithm (All-Pairs Shortest Path):

      • This is a dynamic programming algorithm that finds the shortest paths between all pairs of vertices in a graph.
      • It works by considering every possible pair of vertices and checking if a shorter path exists through an intermediate vertex.
      • Time complexity: O(V3)O(V^3)O(V3), where VVV is the number of vertices.
    4. A Algorithm* (Single-Source, Heuristic):

      • The A* algorithm is used in pathfinding and graph traversal. It combines the best features of Dijkstra’s algorithm and a heuristic approach to find the shortest path more efficiently in certain cases.
      • It uses a heuristic function to guide the search towards the goal.
      • Time complexity: Similar to Dijkstra's but often faster due to the heuristic.
    5. Breadth-First Search (BFS) (Unweighted Graphs):

      • For unweighted graphs, the shortest path between a source and a target can be found using BFS, as it explores all vertices at the present distance before moving to the next level.
      • Time complexity: O(V+E)O(V + E)O(V+E), where VVV is the number of vertices and EEE is the number of edges.

    c) Applications of the Shortest Path Problem

    1. Routing and Navigation:

      • Used in GPS and mapping systems to determine the shortest route between two locations.
    2. Telecommunication Networks:

      • Shortest path algorithms are used to determine the most efficient way to route data packets in communication networks.
    3. Computer Networks:

      • In packet-switching networks, the shortest path is important for minimizing the time or cost required to transfer data between two nodes.
    4. Game AI:

      • Pathfinding algorithms are used in video games to move characters or objects along the shortest path in a grid or map.
    5. Flight Scheduling and Planning:

      • Airlines use shortest path algorithms to determine the most efficient routes between cities.

    3. Differences Between Spanning Trees and Shortest Paths

    Property Spanning Tree Shortest Path
    Definition A subgraph that connects all vertices with no cycles. A path that minimizes the total distance or number of edges between two vertices.
    Purpose To connect all vertices with the minimum number of edges. To find the minimum distance between vertices (either single-source or single-pair).
    Edge Usage Uses V−1V-1V−1 edges, where VVV is the number of vertices. Uses edges with the minimum total weight or fewest edges between two vertices.
    Graph Type Works on connected graphs. Can work on both directed and undirected graphs, with or without edge weights.
    Algorithms Kruskal’s, Prim’s for minimum spanning trees. Dijkstra’s, Bellman-Ford, Floyd-Warshall, BFS for shortest path.
    Complexity Finding a minimum spanning tree is O(Elog⁡V)O(E \log V)O(ElogV) or O(E+Vlog⁡V)O(E + V \log V)O(E+VlogV). Dijkstra’s is O(Elog⁡V)O(E \log V)O(ElogV), Bellman-Ford is O(VE)O(VE)O(VE), Floyd-Warshall is O(V3)O(V^3)O(V3).
    Applications Network design, broadcasting, circuit design. Navigation, network routing, game AI, flight planning.

    4. Summary

    • Spanning Trees: These are subgraphs that connect all the vertices in a graph with the minimum number of edges and no cycles. Minimum spanning trees (MSTs) are particularly useful for minimizing connection costs in networks.

    • Shortest Path Problem: Involves finding the shortest path between vertices, either from a single source to all other vertices or between a specific pair of vertices. Algorithms like Dijkstra's, Bellman-Ford, and Floyd-Warshall are commonly used to solve this problem.

    Both spanning trees and shortest path algorithms play a crucial role in optimizing network designs, routing, and other practical problems related to graph theory.

    Previous topic 21
    Eulerian and Hamiltonian Paths
    Next topic 23
    Revisiting Special Functions: Power, Floor, Increasing, Decreasing

    Past Papers

    Open this section to load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time9 min
      Word count1,506
      Code examples0
      DifficultyIntermediate