0% found this document useful (0 votes)
26 views

Design Analysis Algorithm 4

A graph data structure consists of a collection of vertices connected by edges. Vertices represent nodes that contain data, and edges represent relationships between vertices. A graph is defined as a pair (V,E) where V is the set of vertices and E is the set of edges. Graphs can be directed, with edges having a direction, or undirected, with bidirectional edges. A connected graph is one where every vertex is reachable from every other vertex through a path of edges. Regular graphs have all vertices with the same degree, and complete graphs have an edge between every pair of vertices. Spanning trees are subgraphs that contain all vertices and one fewer edges than a connected graph.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Design Analysis Algorithm 4

A graph data structure consists of a collection of vertices connected by edges. Vertices represent nodes that contain data, and edges represent relationships between vertices. A graph is defined as a pair (V,E) where V is the set of vertices and E is the set of edges. Graphs can be directed, with edges having a direction, or undirected, with bidirectional edges. A connected graph is one where every vertex is reachable from every other vertex through a path of edges. Regular graphs have all vertices with the same degree, and complete graphs have an edge between every pair of vertices. Spanning trees are subgraphs that contain all vertices and one fewer edges than a connected graph.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Graph Data Structure

A graph data structure is a collection of nodes that have data and are connected to other
nodes. Every relationship is an edge from one node to another.
More precisely, a graph is a data structure (V, E) that consists of
• A collection of vertices V
• A collection of edges E, represented as ordered pairs of vertices (u,v)

Vertices and edges


In the graph,

V = {0, 1, 2, 3}
E = {(0,1), (0,2), (0,3), (1,2)}
G = {V, E}

Graph Terminology
• Adjacency: A vertex is said to be adjacent to another vertex if there is an edge
connecting them. Vertices 2 and 3 are not adjacent because there is no edge between
them.
• Path: A sequence of edges that allows you to go from vertex A to vertex B is called a
path. 0-1, 1-2 and 0-2 are paths from vertex 0 to vertex 2.

Directed Graphs
A directed graph is a set of vertices (nodes) connected by edges, with each node having a
direction associated with it.
Edges are usually represented by arrows pointing in the direction the graph can be traversed.

Undirected Graph
In an undirected graph the edges are bidirectional, with no direction associated with them.
Hence, the graph can be traversed in either direction. The absence of an arrow tells us that the
graph is undirected.
Connected Graph
A connected graph is a graph in which there is always a path from a vertex to any other vertex.

Regular Graph
A graph in which degree of all the vertices is same is called as a regular graph.
If all the vertices in a graph are of degree ‘k’, then it is called as a “k-regular graph“.
Examples

In these graphs,
• All the vertices have degree-2.
• Therefore, they are 2-Regular graphs.
Complete Graph
A graph in which exactly one edge is present between every pair of vertices is called as a
complete graph.
A complete graph of ‘n’ vertices is represented as Kn.
Examples

Cycle Graph
A simple graph of ‘n’ vertices (n>=3) and n edges forming a cycle of length ‘n’ is called as a cycle
graph.
In a cycle graph, all the vertices are of degree 2.
Examples

In these graphs,
• Each vertex is having degree 2.

Spanning Tree
A spanning tree is a sub-graph of an undirected connected graph G (V, E) if
• It should contain all vertices of G.
• It should contain (|v| -1) edges.

The total number of spanning trees with n vertices that can be created from a complete graph
is equal to n(n-2) .

If we have n = 4, the maximum number of possible spanning trees is equal to 44-2 = 16. Thus,
16 spanning trees can be formed from a complete graph with 4 vertices.

Example of a Spanning Tree

Let the original graph be:

You might also like