Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
48 views

Graph in Datastructure

This document discusses graphs in data structures. It defines a graph as a collection of vertices connected by edges. It discusses different types of graphs like undirected graphs, directed graphs, and weighted graphs. It also covers graph representation techniques like adjacency matrices and adjacency lists. Common graph algorithms like breadth-first search, depth-first search, Dijkstra's algorithm, and minimum spanning trees are explained. Real-world applications of graphs in areas like social networks and transportation are also mentioned.

Uploaded by

xyush207
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Graph in Datastructure

This document discusses graphs in data structures. It defines a graph as a collection of vertices connected by edges. It discusses different types of graphs like undirected graphs, directed graphs, and weighted graphs. It also covers graph representation techniques like adjacency matrices and adjacency lists. Common graph algorithms like breadth-first search, depth-first search, Dijkstra's algorithm, and minimum spanning trees are explained. Real-world applications of graphs in areas like social networks and transportation are also mentioned.

Uploaded by

xyush207
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Graphs in Data Structure

presented by:-
Ayush Chouhan (0101CS221040)
Understanding Graphs in
in Data Structures
A graph is a non-linear data structure that consists of nodes (vertices) connected by
connected by edges. Learn about different types of graphs, representation
representation techniques, traversal algorithms, and real-world applications.
applications.
Definition of Graphs
1 What is a Graph? 2 Types of Graphs
A graph is a collection of vertices and There are different types of graphs,
edges, where vertices represent entities including undirected graphs, directed
and edges represent relationships graphs, and weighted graphs, each
between them. serving unique purposes.

3 Representing a Graph
Graphs can be represented using adjacency matrices or adjacency lists, providing efficient ways
to store and manipulate graph information.
Graph Traversal Algorithms
1 Breadth-First Search (BFS)
BFS explores the graph starting at the root (source) node and visits all the neighboring
nodes before moving to the next level.

2 Depth-First Search (DFS)


DFS explores the graph by diving deep into a branch and backtracking only when
necessary, effectively searching through the entire graph.

3 Applications of Graphs
Graphs find applications in various domains, such as social networks, modeling web
page relationships, and analyzing data interconnections.
Visualization of Graphs

Network Visualization Road Networks Social Networks


Visualize complex graphs using Graphs can represent road Explore the structure of social
network visualization techniques to networks, enabling efficient route networks and understand the
uncover patterns and gain insights planning, traffic analysis, and dynamics of relationships between
into interconnected data. optimizing transportation systems. individuals or communities.
Graph Theory and Optimization
1 Eulerian and Hamiltonian Paths 2 Minimum Spanning Tree (MST)

Graph theory helps solve problems like MST algorithms find the minimum-weight
finding the most efficient route to visit connected subgraph of a graph, useful in
certain locations (Eulerian Path) or visiting network design, clustering analysis, and
all locations exactly once (Hamiltonian resource allocation.
Path).

3 Graph Coloring
Graph coloring is used in scheduling problems, register allocation, and map labeling, ensuring
that no adjacent nodes have the same color.
Graph Databases and Knowledge Graphs

Graph Databases Knowledge Graphs


Graph databases store information as nodes Knowledge graphs organize information in a
and relationships, allowing for efficient graph format, enabling semantic search,
querying and analysis of highly connected recommendation systems, and knowledge
data. representation.
Challenges and Research in Graph Theory

1 Graph Isomorphism 2 Graph Algorithm 3 Graph Neural


Problem Optimization Networks
Is it possible to determine if Research focuses on Graph neural networks have
two graphs are isomorphic? developing efficient graph emerged
This problem has algorithms, improving
implications in scalability, reducing
cryptography, network computational complexity,
verification, and algorithm and handling large-scale
complexity. graphs.
Definition of a Graph
Vertices and Edges Directed or Undirected Weighted or
Unweighted
Graphs consist of vertices A graph can be directed, where
(nodes) connected by edges edges have a specific direction, Graphs can have weighted
(lines). or undirected, where edges are edges, which assign a value to
bidirectional. each edge, or unweighted
edges, with no assigned values.
Types of Graphs

1 Undirected Graphs 2 Directed Graphs


Edges have no direction and vertices are Edges have a specific direction, indicating a one-
connected bidirectionally. way connection between vertices.

3 Weighted Graphs 4 Cyclic and Acyclic Graphs


Edges are assigned values, indicating the cost, Cyclic graphs contain cycles, while acyclic graphs
distance, or any other relevant attribute. do not have any cycles.
Representing a Graph

Adjacency Matrix Adjacency List Incidence Matrix


A matrix representation using a A linked list representation where A matrix representation using a
two-dimensional array to show the each vertex maintains a list of two-dimensional array to indicate
connections between vertices. adjacent vertices. the presence of edges between
vertices.
Graph Traversal
1 Breadth-First Search (BFS)
Explores all the vertices of a graph level by level using a queue.

2 Depth-First Search (DFS)


Explores as far as possible, backtracking only when no further unvisited vertices are
available.

3 Dijkstra's Algorithm
Finds the shortest path between two vertices in a weighted graph.
Discovering the Marvels of
Graphs
We'll explore the common operations that can be performed on graphs, a powerful
data structure used in many fields, from social networks to transportation systems.
Join me on this journey!
Graph Representation in Memory

Adjacency Matrix Adjacency List


A two-dimensional array that stores a value at position (i, A list of lists, where each vertex i has an associated list of
j) if there's an edge from vertex i to vertex j. its neighbors.
Traversal Algorithms
BFS: Breadth-First Search DFS: Depth-First Search
Explores all vertices at distance d from the Explores as far as possible on each branch
starting vertex before moving to distance before backtracking. Useful for topological
d+1. Useful for shortest path algorithms and sorting and strongly connected components.
connectivity tests.
Topological Sorting
1 What is it?
An ordering of the vertices of a directed acyclic graph (DAG) such that for every
directed edge (u, v), vertex u comes before vertex v in the ordering.

2 Applications:
Dependency resolution, task scheduling, code compilation.

3 Algorithm:
Uses DFS and a stack to reverse the order of the vertices visited in post-order traversal.
Shortest Path Algorithms

Dijkstra's Algorithm Bellman-Ford Algorithm


Explores vertices in order of increasing distance from the Relaxes edges (i, j) repeatedly, relaxing the distance
starting vertex, updating distances as it goes. Requires estimates stored in an array. Detects and handles
non-negative edge weights, but is optimal and faster negative cycles and works with negative edge weights,
than Bellman-Ford. but is slower than Dijkstra's and may give non-optimal
paths in the presence of negative weights.
Minimum Spanning Tree Algorithms
1 What is it?
A tree that spans all the vertices in a connected, undirected graph, with a minimum
total weight. Useful for optimizing networks and communication systems.

2 Prim's Algorithm
Starts with a random vertex, continually adds the cheapest edge to a vertex that hasn't
been visited yet, and stops when all vertices have been visited.

3 Kruskal's Algorithm
Sorts edges by weight, starts with the smallest one, and adds edges only if they don't
form a cycle. Stops when all vertices have been visited.
Graph Connectivity and Strongly
Connected Components
Connectivity: Weakly Connected Components:
A graph is connected if there is a path
between every pair of vertices. The maximal subgraphs of a directed graph
that are connected when all edges are
treated as undirected. Decomposes the
graph into a forest of trees.

Strongly Connected Components:


The maximal subgraphs of a directed graph that are strongly connected, meaning there is a directed
path between every pair of vertices. Useful for finding bottlenecks and clusters in networks.
Graph Coloring and Bipartiteness
1 What is it?
Assigning a color or label to each vertex of a graph, usually so that adjacent vertices
have different colors or labels. Bipartite graphs can be colored with two colors only.

2 Applications:
Scheduling problems, register allocation in compilers, frequency assignment in wireless
networks.

3 Algorithms:
Greedy algorithms work well for many problems, while more complex techniques like
backtracking and constraint programming are used for others.
Types of Graph in Data
Structure
Discover the fascinating world of graph data structures. From basic types to
common algorithms and real-world applications.
Basic Types of Graphs
Undirected Graph Directed Graph
A graph where edges have no direction. A graph where edges have a direction.
Connections between nodes are Connections between nodes are
bidirectional. unidirectional.
Properties of Graphs
Weighted Graph Unweighted Graph Connected and
Disconnected Graphs
A graph where edges have A graph where edges have no
weights or values associated with weights or values associated with
them. them.
A connected graph has a path
between every pair of its vertices.
A disconnected graph has one or
more components that are not
connected.
Common Algorithms for Working with
Graphs
1 Breadth-first Search
An algorithm that explores all vertices of a graph from the starting vertex level by level.

2 Depth-first Search
An algorithm that explores as far as possible along each branch before backtracking.

3 Dijkstra's Algorithm
An algorithm that finds the shortest path between two vertices in a graph with non-negative
edge weights.
Real-world Applications of Graph Data
Structures

Social Networks Transportation Networks Dependencies


Graphs are used to represent Graphs model the interconnected Graphs capture the dependencies
connections between individuals on routes, roads, and destinations in and relationships between tasks or
social media platforms. transportation systems. modules in software development.
Matrix in Graph in Data
Structures
An exploration into the fascinating world of matrices in graph data structures, their
types, applications, and performance considerations.
Importance of Using Matrices in
Data Structures
Matrices in data structures enable efficient access and manipulation of graph-
related information, facilitating various algorithms and computations.
Overview of Graph Data Structure
Graph data structure is a collection of nodes connected by edges. It allows representation and analysis of complex
relationships and networks.
Introduction to Matrix Representation in Graph

Adjacency Matrix Incidence Matrix Distance Matrix


Represents the connections Utilizes a two-dimensional Presents the shortest path
between nodes using a two- array to represent both nodes distances between various
dimensional array, with values and edges, with values nodes in the graph, useful for
indicating the presence or indicating the relationships optimizing pathfinding
absence of an edge. between them. algorithms.
Applications of Matrices in Graph Data
Structures
1 Graph Traversal Algorithms 2 Shortest Path Algorithms
Matrices facilitate efficient traversal Matrices enable the computation of the
algorithms like breadth-first search and shortest path between nodes, such as
depth-first search. Dijkstra's algorithm and Floyd-Warshall
algorithm.

3 Network Flow Algorithms


Matrices aid in optimizing network flow algorithms, which involve finding the maximum or
minimum flow in a network.
Performance Considerations of Using
Matrices in Graphs
Space Complexity Time Complexity
Using matrices can consume significant Some graph operations, like traversing or
space, especially for large graphs, due to the accessing specific edges, can be time-
need for a two-dimensional array. consuming with matrices for graphs with
dense connections.
Common Operations on Graphs
Adding and Removing Vertices and Edges Traversing the Graph
Embark on a journey through the depths and
Embrace the dynamic nature of graphs by breadths of graphs. Unveil the mysteries of depth-
mastering the art of adding and removing vertices first search and breadth-first search.
and edges. Shape your graph's destiny.
Applications of Graphs
1 Social Networks and Connections
Unravel the interconnectedness of our digital lives. Dive into the fascinating world of
social networks powered by graphs.

2 Routing and Shortest Path Algorithms


Unlock the secrets behind efficient routing and navigation. Discover the shortest path
algorithms employed in maps and networks.
Conclusion
As we conclude our exploration of graphs in data structure, we hope you've gained
a deeper appreciation for their versatility and wide-ranging applications. Embrace
the graphical side of data.

You might also like