0% found this document useful (0 votes)
11 views5 pages

Unit 5

The document provides an overview of different types of graphs, including undirected, directed, weighted, and non-weighted graphs, along with essential graph terminology such as nodes, edges, and degrees. It also explains the adjacency matrix representation of graphs, highlighting its structure, advantages, and disadvantages. Additionally, it distinguishes between directed and undirected graphs based on the directionality of their edges.

Uploaded by

Saad Wasta
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)
11 views5 pages

Unit 5

The document provides an overview of different types of graphs, including undirected, directed, weighted, and non-weighted graphs, along with essential graph terminology such as nodes, edges, and degrees. It also explains the adjacency matrix representation of graphs, highlighting its structure, advantages, and disadvantages. Additionally, it distinguishes between directed and undirected graphs based on the directionality of their edges.

Uploaded by

Saad Wasta
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/ 5

UNIT 5

1.Types of graphs

Types of Graphs
Graphs are a fundamental data structure used to represent relationships between entities. They consist of
nodes (vertices) connected by edges. There are several types of graphs, each with its own characteristics and
applications:

1. Undirected Graphs:

 Edges: Edges do not have a direction. If there's an edge between nodes A and B, it means you can go
from A to B or from B to A.
 Example: Social networks, where friends are connected without specifying direction.

2. Directed Graphs:

 Edges: Edges have a direction. If there's an edge from A to B, it means you can go from A to B but
not necessarily from B to A.
 Example: Road networks, where roads have one-way or two-way traffic.

3. Weighted Graphs:

 Edges: Each edge has an associated weight, representing a cost, distance, or other value.
 Example: Road networks with distances between cities, transportation networks with costs.

4.Non-Weighted Graphs

Non-weighted graphs are graphs where the edges do not have associated weights or values. In other words,
there's no quantitative measure associated with the connections between nodes.
2.Graph terminology

Graph Terminology
Here are some common terms used in graph theory:

Nodes (Vertices):

 The individual elements or points within a graph.


 They represent entities or objects in a network.

Edges:

 The connections or relationships between nodes.


 They can be directed (with an arrow indicating direction) or undirected (no arrow).

Degree:

 The number of edges connected to a node.


 In an undirected graph, the degree of a node is the number of edges incident to it.
 In a directed graph, the degree can be divided into:
o In-degree: The number of incoming edges.
o Out-degree: The number of outgoing edges.

Path:

 A sequence of edges that connects two nodes.


 A path can be simple (no repeated nodes) or non-simple (repeated nodes).

Cycle:

 A path that starts and ends at the same node.


 A cycle can be simple (no repeated edges) or non-simple (repeated edges).

Connected Graph:

 A graph where there is a path between every pair of nodes.

Disconnected Graph:

 A graph that is not connected.

Subgraph:

 A subset of nodes and edges from a given graph.Spanning Tree:

 A subgraph that includes all nodes of the original graph and is a tree (connected and acyclic).

Minimum Spanning Tree (MST):

 A spanning tree with the minimum total weight of its edges (for weighted graphs).

Graph Traversal:
 The process of visiting all nodes in a graph. Common algorithms include:
o Breadth-First Search (BFS)
o Depth-First Search (DFS)

Adjacency Matrix:

 A 2D matrix representing a graph, where each element indicates the existence of an edge between two
nodes.

Adjacency List:

 A list representation of a graph, where each node has a list of its adjacent nodes.
3.Adjacency matrix representation of graph

Adjacency Matrix Representation of Graphs


An adjacency matrix is a 2D matrix used to represent a graph. It provides a convenient way to store and
manipulate graph information.

Structure:

 Size: The matrix is typically of size n x n, where n is the number of nodes in the graph.
 Elements: Each element A[i][j] in the matrix represents the connection between nodes i and j:
o 1: If there's an edge between nodes i and j.
o 0: If there's no edge between nodes i and j.

For undirected graphs:

 The matrix is symmetric, meaning A[i][j] is equal to A[j][i].

For directed graphs:

 The matrix is not necessarily symmetric. A[i][j] represents an edge from node i to node j, while
A[j][i] represents an edge from node j to node i.

Example:

Consider the following undirected graph:

A -- B -- C
\ /
D

The adjacency matrix representation would be:

A B C D
A 0 1 1 1
B 1 0 1 1
C 1 1 0 1
D 1 1 1 0

Advantages of Adjacency Matrix:

 Simple to implement and understand.


 Efficient for checking if there's an edge between two nodes.

Disadvantages of Adjacency Matrix:

 Can be inefficient for sparse graphs (graphs with few edges compared to the possible maximum).
 Requires O(n^2) space, even for sparse graphs.
4. directed and undirected graph

Graphs are a fundamental data structure used to represent relationships between entities. They consist of
nodes (vertices) connected by edges. The type of graph depends on the directionality of its edges.

Directed Graphs

 Edges: Edges have a direction, indicating a one-way relationship between the nodes.
 Notation: Edges are often represented with arrows.
 Example: Road networks with one-way streets, social networks with followers, and state transition
diagrams.

Undirected Graphs

 Edges: Edges do not have a direction, indicating a two-way relationship between the nodes.
 Notation: Edges are often represented without arrows.
 Example: Friendship networks, geographic maps, and electrical circuits.

You might also like