# Graph Data Structure And Algorithms

** Graph Data Structure** is a collection of

**connected by**

**nodes****. It’s used to represent relationships between different entities.**

**edges****are methods used to manipulate and analyze graphs, solving various problems like**

**Graph algorithms****or**

**finding the shortest path**

**detecting cycles.**Table of Content

- What is Graph Data Structure?
- Components of a Graph
- Basic Operations on Graphs
- Applications of Graph
- Basics of Graph
- BFS and DFS in Graph
- Cycles in Graph
- Shortest Path in Graph
- Minimum Spanning Tree
- Topological Sorting
- Connectivity in Graph
- Maximum Flow in Graph
- Some must do Problems on Graph
- Some Quizzes

## What is Graph Data Structure?

Graph is a non-linear data structure consisting of vertices and edges. The vertices are sometimes also referred to as nodes and the edges are lines or arcs that connect any two nodes in the graph. More formally aÂ GraphÂ is composed of a set of vertices(Â ** VÂ **) and a set of edges(Â

**). The graph is denoted byÂ**

**EÂ**

**G(V, E).**Graph data structures are a powerful tool for representing and analyzing complex relationships between objects or entities. They are particularly useful in fields such as social network analysis, recommendation systems, and computer networks. In the field of sports data science, graph data structures can be used to analyze and understand the dynamics of team performance and player interactions on the field.

## Components of a Graph:

Â Vertices are the fundamental units of the graph. Sometimes, vertices are also known as vertex or nodes. Every node/vertex can be labeled or unlabeled.**Vertices:**Â Edges are drawn or used to connect two nodes of the graph. It can be ordered pair of nodes in a directed graph. Edges can connect any two nodes in any possible way. There are no rules. Sometimes, edges are also known as arcs. Every edge can be labelled/unlabelled.**Edges:**

## Basic Operations on Graphs:

Below are the basic operations on the graph:

- Insertion of Nodes/Edges in the graph â€“ Insert a node into the graph.
- Deletion of Nodes/Edges in the graph â€“ Delete a node from the graph.
- Searching on Graphs â€“ Search an entity in the graph.
- Traversal of Graphs â€“ Traversing all the nodes in the graph.

## Applications of Graph:

**Following are the real-life applications:**

**Following are the real-life applications:**

- Â Graph data structures can be used to represent the interactions between players on a team, such as passes, shots, and tackles. Analyzing these interactions can provide insights into team dynamics and areas for improvement.
- Commonly used to represent social networks, such as networks of friends on social media.
- Graphs can be used to represent the topology of computer networks, such as the connections between routers and switches.
- Graphs are used to represent the connections between different places in a transportation network, such as roads and airports.
- Graphs are used in Neural Networks where vertices represent neurons and edges represent the synapses between them. Neural networks are used to understand how our brain works and how connections change when we learn. The human brain has about 10^11 neurons and close to 10^15 synapses.

**Basics of Graph:**

**Basics of Graph:**

- Introduction to Graphs
- Graph and its representations
- Types of Graphs with Examples
- Basic Properties of a Graph
- Applications, Advantages and Disadvantages of Graph
- Transpose graph
- Difference between graph and tree

**BFS and DFS in Graph:**

**BFS and DFS in Graph:**

- Breadth First Traversal for a Graph
- Depth First Traversal for a Graph
- Applications of Depth First Search
- Applications of Breadth First Traversal
- Iterative Depth First Search
- BFS for Disconnected Graph
- Transitive Closure of a Graph using DFS
- Difference between BFS and DFS

**Cycles in Graph:**

**Cycles in Graph:**

- Detect Cycle in a Directed Graph
- Detect cycle in an undirected graph
- Detect cycle in a direct graph using colors
- Detect a negative cycle in a Graph | (Bellman Ford)
- Cycles of length n in an undirected and connected graph
- Detecting negative cycle using Floyd Warshall
- Clone a Directed Acyclic Graph
- Union By Rank and Path Compression in Union-Find Algorithm
- Introduction to Disjoint Set Data Structure or Union-Find Algorithm

**Shortest Path in Graph:**

**Shortest Path in Graph:**

- Dijkstraâ€™s shortest path algorithm
- Bellmanâ€“Ford Algorithm
- Floyd Warshall Algorithm
- Johnsonâ€™s algorithm for All-pairs shortest paths
- Shortest Path in Directed Acyclic Graph
- Dialâ€™s Algorithm
- Multistage Graph (Shortest Path)
- Shortest path in an unweighted graph
- Karpâ€™s minimum mean (or average) weight cycle algorithm
- 0-1 BFS (Shortest Path in a Binary Weight Graph)
- Find minimum weight cycle in an undirected graph

**Minimum Spanning Tree:**

**Minimum Spanning Tree:**

- Primâ€™s Minimum Spanning Tree (MST)
- Kruskalâ€™s Minimum Spanning Tree Algorithm
- Difference between Primâ€™s and Kruskalâ€™s algorithm for MST
- Applications of Minimum Spanning Tree Problem
- Minimum cost to connect all cities
- Total number of Spanning Trees in a Graph
- Minimum Product Spanning Tree
- Reverse Delete Algorithm for Minimum Spanning Tree
- Boruvkaâ€™s algorithm for Minimum Spanning Tree

**Topological Sorting:**

**Topological Sorting:**

- Topological Sorting
- All topological sorts of a Directed Acyclic Graph
- Kahnâ€™s Algorithm for Topological Sorting
- Maximum edges that can be added to DAG so that is remains DAG
- Longest Path in a Directed Acyclic Graph
- Topological Sort of a graph using departure time of vertex

**Connectivity in Graph:**

**Connectivity in Graph:**

- Articulation Points (or Cut Vertices) in a Graph
- Biconnected Components
- Bridges in a graph
- Eulerian path and circuit
- Fleuryâ€™s Algorithm for printing Eulerian Path or Circuit
- Strongly Connected Components
- Count all possible walks from a source to a destination with exactly k edges
- Euler Circuit in a Directed Graph
- Length of shortest chain to reach the target word
- Find if an array of strings can be chained to form a circle
- Tarjanâ€™s Algorithm to find strongly connected Components
- Paths to travel each nodes using each edge (Seven Bridges of KÃ¶nigsberg)
- Dynamic Connectivity | Set 1 (Incremental)

**Maximum Flow in Graph:**

**Maximum Flow in Graph:**

- Max Flow Problem Introduction
- Ford-Fulkerson Algorithm for Maximum Flow Problem
- Find maximum number of edge disjoint paths between two vertices
- Find minimum s-t cut in a flow network
- Maximum Bipartite Matching
- Channel Assignment Problem
- Introduction to Push Relabel Algorithm
- Kargerâ€™s Algorithm- Set 1- Introduction and Implementation
- Dinicâ€™s algorithm for Maximum Flow

**Some must do Problems on Graph:**

**Some must do Problems on Graph:**

- Find length of the largest region in Boolean Matrix
- Count number of trees in a forest
- A Peterson Graph Problem
- Clone an Undirected Graph
- Graph Coloring (Introduction and Applications)
- Traveling Salesman Problem (TSP) Implementation
- Vertex Cover Problem | Set 1 (Introduction and Approximate Algorithm)
- K Centers Problem | Set 1 (Greedy Approximate Algorithm)
- Erdos Renyl Model (for generating Random Graphs)
- Chinese Postman or Route Inspection | Set 1 (introduction)
- Hierholzerâ€™s Algorithm for directed graph
- Check whether a given graph is Bipartite or not
- Snake and Ladder Problem
- Boggle (Find all possible words in a board of characters)
- Hopcroft Karp Algorithm for Maximum Matching-Introduction
- Minimum Time to rot all oranges
- Construct a graph from given degrees of all vertices
- Determine whether a universal sink exists in a directed graph
- Number of sink nodes in a graph
- Two Clique Problem (Check if Graph can be divided in two Cliques)

**Some Quizzes:**

**Some Quizzes:**

- Quizzes on Graph Traversal
- Quizzes on Graph Shortest Path
- Quizzes on Graph Minimum Spanning Tree
- Quizzes on Graphs

**Quick Links :**

- Top 10 Interview Questions on Depth First Search (DFS)
- Some interesting shortest path questions
- Practice Problems on Graphs
- Videos on Graphs

**Recommended:**