# Graph Data Structure And Algorithms

**Learn more about Graph in DSA Self Paced Course**

**Practice Problems on Graphs**

**Recent Articles on Graph**

## What is Graph Data Structure?

A 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( E ). The graph is denoted by G(E, V).

## Components of a Graph

**Vertices:**Vertices are the fundamental units of the graph. Sometimes, vertices are also known as vertex or nodes. Every node/vertex can be labeled or unlabelled.**Edges:**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 labeled/unlabelled.

Graphs are used to solve many real-life problems. Graphs are used to represent networks. The networks may include paths in a city or telephone network or circuit network. Graphs are also used in social networks like linkedIn, Facebook. For example, in Facebook, each person is represented with a vertex(or node). Each node is a structure and contains information like person id, name, gender, locale etc.

**Topics**:

- 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

- 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

- 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

- 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

- 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
- 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

- 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)

- 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:**

- 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)

- Top 10 Interview Questions on Depth First Search (DFS)
- Some interesting shortest path questions
- Quizzes on Graph Traversal
- Quizzes on Graph Shortest Path
- Quizzes on Graph Minimum Spanning Tree
- Quizzes on Graphs
- Practice Problems on Graphs
- Videos on Graphs

### GeeksforGeeks Courses:

1. Language Foundation Courses [C++ / JAVA / Python ]

Learn any programming language from scratch and understand all its fundamentals concepts for a strong programming foundation in the easiest possible manner with help of GeeksforGeeks Language Foundation Courses – Java Foundation | Python Foundation | C++ Foundation

2.Complete Interview Preparation

Get fulfilled all your interview preparation needs at a single place with theComplete Interview Preparation Coursethat provides you all the required stuff to prepare for any product-based, service-based, or start-up company at the most affordable prices.

3.DSA Self Paced

Start learning Data Structures and Algorithms to prepare for the interviews of top IT giants like Microsoft, Amazon, Adobe, etc. withDSA Self-Paced Coursewhere you will get to learn and master DSA from basic to advanced level and that too at your own pace and convenience.

4. Company Specific Courses – Amazon & Microsoft

Crack the interview of any product-based giant company by specifically preparing with the questions that these companies usually ask in their coding interview round. Refer GeeksforGeeks Company Specific Courses: Amazon SDE Test Series, etc.

**Recomended:**

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.