Professional Documents
Culture Documents
Lecture 15
Lecture 15
1
RECAP
Array Operations
Operation on array
• Traversing (accessing each element at least once)
• Insertion
• Deletion
• Searching
• Sorting
Bubble Sort
Selection Sort
Insertion Sort
Radix Sort
Counting Sort
• Stack
Polish Notation
Reversion Polish Notation
Evaluation
• Queue
• Link List
• Hash Function
• Tree
Applications of Tree Data
Structure
Applications of Tree Data Structure
Machine Learning
Relationship
Applications of Tree Data Structure
Folders Hierarchy System in Computers
GRAPH
Types of Graph -
A graph is a collection of nodes (or vertices, singular is vertex) and
edges (or arcs)
G = (V, E)
In this graph,
V={A,B,C,D,E}
E = { AB , AC , BD , CD , DE }
TERMENOLOGIES
Terminologies
Node/Vertex: Each element of a graph is called node/vertex of a graph
Edge/Arc: Line joining two nodes is called an edge
Terminologies
Degree of a Node: The degree of a node is the number of edges it has.
Parallel Edges: Two or more edges joining a pair of vertices
Example:
A graph with vertices labelled by degree A and B nodes are joined by two parallel edges
Terminologies
Graph Size: The size of a graph is the number of edges in it, it is denoted as |
E|
Order of Graph: The order of the graph is the total number of nodes, it is
denoted as : |V|
Neighbor Vertices / Adjacent Vertices: If two nodes are connected by an
edge, they are neighbors (and the nodes are adjacent to each other).
Example:
6
Birmingham Rugby
0 Example: (London, Bristol,
150 Birmingham, London, Dover) is a
190 100
140 Cambridge path
London Example: (London, Bristol,
190 120
Birmingham, London) is a cycle
Bristol 110 Dover
Southampton
TYPES OF GRAPH
Types of Graph
There are many various types of graph are-
Types of Graph -
Non-Directed Graph –
A graph in which all the edges are undirected is called as a non-directed graph.
In other words, edges of an undirected graph do not contain any direction.
Example-
Here,
This graph consists of four vertices and four undirected edges.
Since all the edges are undirected, therefore it is a non-directed graph.
Types of Graph -
Directed Graph –
A graph in which all the edges are directed is called as a directed graph.
In other words, all the edges of a directed graph contain some direction.
Directed graphs are also called as digraphs.
Example-
Here,
This graph consists of four vertices and four directed edges.
Since all the edges are directed, therefore it is a directed graph.
Types of Graph -
Connected Graph
A graph in which we can visit from any one vertex to any other vertex is called
as a connected graph.
In connected graph, at least one path exists between every pair of vertices.
Example-
Here,
In this graph, we can visit from any one vertex to any other vertex.
There exists at least one path between every pair of vertices.
Therefore, it is a connected graph.
Types of Graph -
Disconnected Graph
A graph in which we can’t visit from any one vertex to any other vertex is called
as a connected graph.
Example-
Here,
This graph consists of two independent components which are disconnected.
It is not possible to visit from the vertices of one component to the vertices of
other component.
Therefore, it is a disconnected graph.
Types of Graph -
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“.
Example-
Here,
In these graphs,
All the vertices have degree-2.
Therefore, they are 2-Regular graphs.
Binary Search Tree -
Complete Graph-
A complete graph is a graph in which each vertex is connected to every other
vertex. That is, a complete graph is an undirected graph where every pair of
distinct vertices is connected by a unique edge. This is the complete graph
definition.
Example-
In these graphs,
Each vertex is connected with all the remaining vertices.
Types of Graph -
Acyclic Graph-
A graph not containing any cycle in it is called as an acyclic graph.
Example-
Types of Graph -
Weighted Graph
A graph where each edge is assigned a numerical label or “weight”.
Example-
THANKS