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.
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.
A graph is defined as a pair , where:
Edges can be:
For example:
Simple Graph: A graph with no loops (edges from a vertex to itself) and no multiple edges between two vertices.
Multigraph: A graph that may have multiple edges between the same pair of vertices.
Complete Graph: A graph where every pair of distinct vertices is connected by a unique edge.
Weighted Graph: A graph in which each edge has an associated weight (often used to represent costs, distances, or capacities).
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.
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.
Planar Graph: A graph that can be drawn on a plane without any edges crossing.
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.
A tree is a connected, undirected graph with no cycles. A tree with vertices has exactly 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.
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.
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.
AVL Tree: A self-balancing binary search tree where the heights of the two child subtrees of any node differ by at most one.
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.
Trie: A tree used to store strings, where each node represents a character, and the tree allows efficient searching and prefix matching.
Spanning Tree: A subgraph of a graph that includes all the vertices of the original graph and forms a tree.
Graphs and trees are fundamental in many algorithms. Some important algorithms related to graphs include:
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.
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.
Dijkstra’s Algorithm: An algorithm for finding the shortest path between nodes in a graph with weighted edges.
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.
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.
Topological Sorting: A linear ordering of vertices in a directed graph such that for every directed edge , vertex comes before vertex . This is useful in tasks like task scheduling.
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.
Routing Algorithms: Graph algorithms like Dijkstra’s are used in routing protocols (e.g., for finding the shortest path between two network nodes).
Hierarchical Data: Trees are used to represent hierarchical data structures such as organizational charts, file systems, and XML documents.
Social Networks: Graphs represent relationships between individuals in social networks, where vertices represent people, and edges represent social connections.
Compiler Design: Trees are used in parsing expressions and syntax trees (e.g., abstract syntax trees) in compiler construction.
Open this section to load past papers