DS2 Module 7
DS2 Module 7
DISCRETE STRUCTURE
Connectivity
1. Connected Graphs:
Undirected Graph: A graph is connected if there's a path between every pair
of vertices.
Directed Graph:
o Strongly Connected: Path exists between every pair of vertices in both
directions.
o Weakly Connected: Path exists in at least one direction.
2. Components:
Connected Component: A maximal subset of vertices such that every pair
within it is connected.
Strongly Connected Component (SCC): A maximal subset of vertices such
that every pair within it has a bidirectional path.
Algorithms:
DFS/BFS: To determine connectivity.
Kosaraju’s Algorithm: To find SCCs in directed graphs.
Graph Optimization
Optimization problems deal with finding the best solution under constraints:
1. Shortest Path Algorithms:
Dijkstra’s Algorithm: Single-source shortest path (non-negative weights).
Bellman-Ford Algorithm: Handles negative weights.
Ericka Mae C. Sabaybay
Instructor
ASSOCIATE IN COMPUTER TECHNOLOGY
DISCRETE STRUCTURE
What is a Tree?
1.1 Definition:
A tree is a connected, undirected graph with no cycles.
Alternatively, a tree can be defined as:
o A graph with n vertices and n−1 edges that is acyclic and connected.
1.2 Properties of Trees:
1. Unique Path: Between any two vertices, there is exactly one path.
2. Connected and Acyclic: Trees are always connected and contain no cycles.
3. Edges and Vertices: If a tree has n vertices, it will have n−1 edges.
4. Subtrees: Removing any edge splits a tree into two disconnected subtrees.
5. Degree: Trees often feature nodes with varying degrees, from leaves (degree
1) to higher-degree nodes like roots.
1.3 Applications of Trees:
Hierarchical Representation: File systems, organization charts.
Data Structure Basis: Binary search trees (BST), heaps.
Networking: Spanning trees in network design.
Algorithms: Tree traversals, Huffman coding, etc.
Spanning Trees
2.1 Definition:
A spanning tree is a subgraph of a connected graph that:
Includes all vertices of the original graph.
Is a tree (connected and acyclic).
Has n−1 edges, where n is the number of vertices in the graph.
2.2 Types of Spanning Trees:
1. Minimum Spanning Tree (MST):
o A spanning tree with the minimum possible sum of edge weights.
o Algorithms: Kruskal’s, Prim’s.
2. Maximum Spanning Tree:
o A spanning tree with the maximum possible sum of edge weights.
2.3 Properties:
1. Any connected graph can have multiple spanning trees.
2. A spanning tree preserves the graph's connectivity with no cycles.
2.4 Applications:
Network Design: Minimizing cable/connection costs.
Ericka Mae C. Sabaybay
Instructor
ASSOCIATE IN COMPUTER TECHNOLOGY
DISCRETE STRUCTURE
Rooted Trees
3.1 Definition:
A rooted tree is a tree with a designated root node, making the edges and vertices
hierarchical.
3.2 Terminology:
1. Root: The topmost node.
2. Parent and Child: A node connected above (parent) or below (child).
3. Leaf Nodes: Nodes with no children.
4. Internal Nodes: Nodes with at least one child.
5. Height: Length of the longest path from the root to a leaf.
6. Depth: Distance of a node from the root.
3.3 Properties:
1. The number of edges from the root to a node is the node’s depth.
2. Subtrees can be formed by choosing any node as the root.
3.4 Applications:
Representing hierarchical data (e.g., organization charts).
Search structures (e.g., binary search trees, tries).
Parse trees in compilers.
Binary Trees
A binary tree is a rooted tree where every node has at most two children.
4.1 Types of Binary Trees:
1. Full Binary Tree:
o Every node has either 0 or 2 children.
o Total nodes: 2k−1, where k is the number of levels.
2. Complete Binary Tree:
o All levels are completely filled except possibly the last, filled from left to
right.
3. Perfect Binary Tree:
o A full binary tree with all leaves at the same depth.
4. Skewed Binary Tree:
o All nodes have only one child (either left or right).
5. Balanced Binary Tree:
o Height difference between left and right subtrees is at most 1 for every
node.
4.2 Properties of Binary Trees: