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 Structures
    CSI-303
    Progress0 / 21 topics
    Topics
    1. Introduction to Logic and Proofs2. Direct Proofs3. Proof by Contradiction4. Sets5. Combinatorics6. Sequences7. Formal Logic8. Propositional and Predicate Calculus9. Methods of Proof10. Mathematical Induction and Recursion11. Loop Invariants12. Relations and Functions13. Pigeonhole Principle14. Trees and Graphs15. Elementary Number Theory16. Optimization and Matching17. Fundamental Structures18. Functions19. Relations (Recursions)20. Cardinality and Countability21. Probabilistic Methods
    CSI-303›Trees and Graphs
    Discrete StructuresTopic 14 of 21

    Trees and Graphs

    8 minread
    1,387words
    Intermediatelevel

    Trees and Graphs in Discrete Mathematics

    In discrete mathematics, trees and graphs are fundamental data structures that are widely used to represent relationships between elements, solve problems in computer science, and model a variety of systems like networks, hierarchies, and flow systems. Trees are a special type of graph, and understanding their properties and relationships with graphs is essential for solving many discrete mathematics problems.


    Graphs

    A graph is a collection of vertices (also called nodes) and edges (also called arcs) that connect pairs of vertices. Graphs are used to represent relationships, networks, or systems of connected entities.

    Definition of a Graph

    A graph GGG is defined as a pair G=(V,E)G = (V, E)G=(V,E), where:

    • VVV is the set of vertices (or nodes).
    • EEE is the set of edges (or arcs), where each edge connects two vertices in VVV.

    Edges can be:

    • Directed: An edge has a direction, going from one vertex to another (called a directed graph or digraph).
    • Undirected: An edge does not have a direction; it connects two vertices in both directions (called an undirected graph).

    For example:

    • A directed graph might have edges like (u,v)(u, v)(u,v) and (v,w)(v, w)(v,w), indicating a one-way relationship from vertex uuu to vertex vvv, and from vertex vvv to vertex www.
    • An undirected graph might have edges like {u,v}\{u, v\}{u,v}, indicating a two-way relationship between vertices uuu and vvv.

    Types of Graphs

    1. Simple Graph: A graph with no loops (edges from a vertex to itself) and no multiple edges between two vertices.

    2. Multigraph: A graph that may have multiple edges between the same pair of vertices.

    3. Complete Graph: A graph where every pair of distinct vertices is connected by a unique edge.

    4. Weighted Graph: A graph in which each edge has an associated weight (often used to represent costs, distances, or capacities).

    5. Connected Graph: An undirected graph where there is a path between every pair of vertices. If a graph is not connected, it is called a disconnected graph.

    6. Bipartite Graph: A graph where the vertices can be divided into two disjoint sets such that no two vertices within the same set are adjacent.

    7. Planar Graph: A graph that can be drawn on a plane without any edges crossing.

    Graph Terminology

    • Adjacent Vertices: Two vertices are adjacent if they are connected by an edge.
    • Degree of a Vertex: The degree of a vertex is the number of edges connected to it. In a directed graph, there are two types of degree:
      • In-degree: The number of incoming edges to a vertex.
      • Out-degree: The number of outgoing edges from a vertex.
    • Path: A sequence of vertices where each consecutive pair is connected by an edge.
    • Cycle: A path that starts and ends at the same vertex without repeating any edges or vertices (except for the starting and ending vertex).
    • Connected Components: A subgraph where there is a path between every pair of vertices within that subgraph.

    Trees

    A tree is a special type of graph that has no cycles and is connected. Trees are hierarchical structures that have a root and a branching structure, and they are commonly used to represent organizational hierarchies, decision trees, file systems, and more.

    Definition of a Tree

    A tree is a connected, undirected graph with no cycles. A tree with nnn vertices has exactly n−1n - 1n−1 edges.

    A rooted tree has a designated vertex called the root, which serves as the starting point of the tree. From the root, other vertices are connected in a hierarchical manner.

    Properties of Trees

    1. No Cycles: Trees do not contain cycles, making them acyclic.
    2. Unique Path: There is exactly one path between any two vertices in a tree, making them useful for representing hierarchies and structure.
    3. Vertices and Edges: A tree with nnn vertices has exactly n−1n - 1n−1 edges.
    4. Leaf Nodes: A leaf is a vertex with no children in a rooted tree (i.e., a vertex with degree 1, except for the root).
    5. Subtrees: Any tree can be viewed as a collection of smaller trees (called subtrees), formed by a vertex and its descendants.
    6. Rooted Tree: In a rooted tree, each node has a parent (except for the root), and the edges represent the "parent-child" relationship.

    Types of Trees

    1. Binary Tree: A tree where each node has at most two children, often referred to as the "left" and "right" children. Binary trees are fundamental in computer science for search algorithms and data storage.

    2. Binary Search Tree (BST): A binary tree where for every node, the value of the left child is less than the value of the parent, and the value of the right child is greater than the value of the parent. This property allows for efficient searching and sorting.

    3. AVL Tree: A self-balancing binary search tree where the heights of the two child subtrees of any node differ by at most one.

    4. Heap Tree: A binary tree used for implementing priority queues, where each parent node is either greater (in a max heap) or smaller (in a min heap) than its children.

    5. Trie: A tree used to store strings, where each node represents a character, and the tree allows efficient searching and prefix matching.

    6. Spanning Tree: A subgraph of a graph that includes all the vertices of the original graph and forms a tree.


    Graph Algorithms

    Graphs and trees are fundamental in many algorithms. Some important algorithms related to graphs include:

    1. Depth-First Search (DFS): An algorithm for traversing or searching a graph. It starts at a source vertex and explores as far as possible along each branch before backtracking.

    2. Breadth-First Search (BFS): An algorithm for traversing or searching a graph. It starts at a source vertex and explores all its neighbors level by level, moving outward from the source.

    3. Dijkstra’s Algorithm: An algorithm for finding the shortest path between nodes in a graph with weighted edges.

    4. Kruskal’s Algorithm: An algorithm for finding the minimum spanning tree of a graph, which connects all vertices with the minimum possible total edge weight.

    5. Prim’s Algorithm: Another algorithm for finding the minimum spanning tree, starting with an arbitrary node and expanding the tree by adding edges with the smallest weight.

    6. Topological Sorting: A linear ordering of vertices in a directed graph such that for every directed edge (u,v)(u, v)(u,v), vertex uuu comes before vertex vvv. This is useful in tasks like task scheduling.


    Applications of Trees and Graphs

    1. Computer Networks: Graphs model networks like the internet or local area networks, where vertices represent routers or computers, and edges represent the connections between them.

    2. Routing Algorithms: Graph algorithms like Dijkstra’s are used in routing protocols (e.g., for finding the shortest path between two network nodes).

    3. Hierarchical Data: Trees are used to represent hierarchical data structures such as organizational charts, file systems, and XML documents.

    4. Social Networks: Graphs represent relationships between individuals in social networks, where vertices represent people, and edges represent social connections.

    5. Compiler Design: Trees are used in parsing expressions and syntax trees (e.g., abstract syntax trees) in compiler construction.


    Conclusion

    • Graphs are versatile structures used to model relationships and networks. They can be directed or undirected, and can have various properties such as being weighted or connected.
    • Trees are a special type of graph with no cycles, often used in applications involving hierarchical relationships, such as in computer science, file systems, and decision-making.
    • Understanding the properties of trees and graphs, along with their algorithms, is crucial for solving problems in computer science, discrete mathematics, and other fields involving complex systems or networks.
    Previous topic 13
    Pigeonhole Principle
    Next topic 15
    Elementary Number Theory

    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 time8 min
      Word count1,387
      Code examples0
      DifficultyIntermediate