0% found this document useful (0 votes)
9 views6 pages

DS2 Module 7

The document provides an overview of graphs, including definitions, types, and key terms, as well as data structures for efficient representation. It covers connectivity concepts, traversals, graph optimization algorithms, and details on trees, spanning trees, rooted trees, and binary trees. Each section highlights properties, applications, and algorithms relevant to the study of discrete structures in computer technology.

Uploaded by

misserickamae14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

DS2 Module 7

The document provides an overview of graphs, including definitions, types, and key terms, as well as data structures for efficient representation. It covers connectivity concepts, traversals, graph optimization algorithms, and details on trees, spanning trees, rooted trees, and binary trees. Each section highlights properties, applications, and algorithms relevant to the study of discrete structures in computer technology.

Uploaded by

misserickamae14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

ASSOCIATE IN COMPUTER TECHNOLOGY

DISCRETE STRUCTURE

Graphs - General Introduction


A graph G is a mathematical structure consisting of:
 Vertices (nodes): V, a set of elements (e.g., V={v1,v2,…,vn} ).
 Edges: E, a set of connections between vertices (e.g., E={(vi,vj)}).
Types of Graphs:
1. Undirected Graphs: Edges have no direction.
2. Directed Graphs (Digraphs): Edges have a direction.
3. Weighted Graphs: Edges have weights or costs associated with them.
4. Simple Graphs: No loops or multiple edges.
5. Multigraphs: Allow multiple edges between two vertices.
6. Complete Graphs: Every pair of vertices is connected by an edge.
Key Terms:
 Degree of a Vertex: Number of edges incident to it (in-degree and out-
degree for directed graphs).
 Subgraph: A subset of V and E that forms a graph.
 Path: A sequence of edges connecting vertices.
 Cycle: A path that starts and ends at the same vertex.

Data Structures for Graphs


Efficient representation of graphs is crucial for computations:
1. Adjacency Matrix:
 A 2D array A[i][j] where:
o A[i][j]=1 (or weight for weighted graphs) if there is an edge from i to j.
o Space complexity: O(V2)
o Suitable for dense graphs.
2. Adjacency List:
 An array of lists:
o Each index represents a vertex, and the list at that index stores adjacent
vertices.
o Space complexity: O(V+E)
o Preferred for sparse graphs.
3. Edge List:
 A list of all edges (u,v,w) (where w is the weight).
 Space complexity: O(E)
 Useful for algorithms like Kruskal’s.

Ericka Mae C. Sabaybay


Instructor
ASSOCIATE IN COMPUTER TECHNOLOGY
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.

Traversals - Eulerian and Hamiltonian Graphs


1. Eulerian Graph:
 Eulerian Path: Visits every edge exactly once.
 Eulerian Circuit: Eulerian Path that starts and ends at the same vertex.
 Conditions:
o Undirected graph:
 Eulerian Circuit: All vertices have an even degree.
 Eulerian Path: Exactly two vertices have odd degrees.
o Directed graph: Strongly connected and each vertex’s in-degree
equals out-degree.
2. Hamiltonian Graph:
 Hamiltonian Path: Visits every vertex exactly once.
 Hamiltonian Circuit: Hamiltonian Path that starts and ends at the same vertex.
 No General Theorem: Determining whether a Hamiltonian Path/Circuit exists is
NP-complete.

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

 Floyd-Warshall Algorithm: All-pairs shortest paths.


2. Minimum Spanning Tree (MST):
 Prim’s Algorithm: Greedy algorithm to find MST.
 Kruskal’s Algorithm: Greedy algorithm using edge sorting.
3. Network Flow Problems:
 Maximum Flow: Ford-Fulkerson or Edmonds-Karp Algorithm.
 Min-Cut: Relates to Maximum Flow (Max-Flow Min-Cut Theorem).
4. Matching Problems:
 Bipartite Matching: Maximum matching in bipartite graphs (Hopcroft-Karp
Algorithm).
5. Traveling Salesman Problem (TSP):
 NP-hard optimization problem.
 Approximation algorithms: Nearest neighbor, Christofides.

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

 Cluster Analysis: Grouping data into clusters in machine learning.


 Electrical Circuits: Minimizing wiring in circuit layouts.

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:

Ericka Mae C. Sabaybay


Instructor
ASSOCIATE IN COMPUTER TECHNOLOGY
DISCRETE STRUCTURE

o Height difference between left and right subtrees is at most 1 for every
node.
4.2 Properties of Binary Trees:

1. Maximum nodes at level 𝑙: 2


2. Maximum nodes in a binary tree of height h: 2 −1

3. Minimum height for n nodes: ⌈𝑙𝑜𝑔 (𝑛 + 1)-1


4.3 Binary Tree Traversals:
1. Inorder (Left, Root, Right):
o Used in sorting binary search trees.
2. Preorder (Root, Left, Right):
o Used in expression trees and creating prefix expressions.
3. Postorder (Left, Right, Root):
o Used in evaluating expressions.
4. Level Order:
o Visits nodes level by level using a queue.
4.4 Applications of Binary Trees:
 Binary Search Trees (BST):
o Efficient for searching, insertion, and deletion O(logn) average case).
 Heaps:
o Used in priority queues and heapsort.
 Huffman Trees:
o Used for optimal data compression.
 Expression Trees:
o Represent algebraic expressions for evaluation.

Ericka Mae C. Sabaybay


Instructor

You might also like