Graph Data Structure And Algorithms

  • Last Updated : 18 Jun, 2022

Data Structure and Algorithms Course
Practice Problems on Graphs
Recent Articles on Graph

A Graph is a non-linear data structure consisting of nodes and edges. The nodes are sometimes also referred to as vertices and the edges are lines or arcs that connect any two nodes in the graph. More formally a Graph can be defined as,

A Graph consists of a finite set of vertices(or nodes) and set of Edges which connect a pair of nodes.

In the above Graph, the set of vertices V = {0,1,2,3,4} and the set of edges E = {01, 12, 23, 34, 04, 14, 13}.

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.


Introduction, DFS and BFS :

  1. Graph and its representations
  2. Breadth First Traversal for a Graph
  3. Depth First Traversal for a Graph
  4. Applications of Depth First Search
  5. Applications of Breadth First Traversal
  6. Graph representations using set and hash
  7. Find Mother Vertex in a Graph
  8. Transitive Closure of a Graph using DFS
  9. Find K cores of an undirected Graph
  10. Iterative Depth First Search
  11. Count the number of nodes at given level in a tree using BFS
  12. Count all possible paths between two vertices
  13. Minimum initial vertices to traverse whole matrix with given conditions
  14. Shortest path to reach one prime to other by changing single digit at a time
  15. Water Jug problem using BFS
  16. Count number of trees in a forest
  17. BFS using vectors & queue as per the algorithm of CLRS
  18. Level of Each node in a Tree from source node
  19. Construct binary palindrome by repeated appending and trimming
  20. Transpose graph
  21. Path in a Rectangle with Circles
  22. Height of a generic tree from parent array
  23. BFS using STL for competitive coding
  24. DFS for a n-ary tree (acyclic graph) represented as adjacency list
  25. Maximum number of edges to be added to a tree so that it stays a Bipartite graph
  26. A Peterson Graph Problem
  27. Implementation of Graph in JavaScript
  28. Print all paths from a given source to a destination using BFS
  29. Minimum number of edges between two vertices of a Graph
  30. Count nodes within K-distance from all nodes in a set
  31. Bidirectional Search
  32. Minimum edge reversals to make a root
  33. BFS for Disconnected Graph
  34. Move weighting scale alternate under given constraints
  35. Best First Search (Informed Search)
  36. Number of pair of positions in matrix which are not accessible
  37. Maximum product of two non-intersecting paths in a tree
  38. Delete Edge to minimize subtree sum difference
  39. Find the minimum number of moves needed to move from one cell of matrix to another
  40. Minimum steps to reach target by a Knight | Set 1
  41. Minimum number of operation required to convert number x into y
  42. Minimum steps to reach end of array under constraints
  43. Find the smallest binary digit multiple of given number
  44. Roots of a tree which give minimum height
  45. Stepping Numbers
  46. Clone an Undirected Graph
  47. Sum of the minimum elements in all connected components of an undirected graph
  48. Check if two nodes are on same path in a tree
  49. A matrix probability question
  50. Find length of the largest region in Boolean Matrix
  51. Iterative Deepening Search(IDS) or Iterative Deepening Depth First Search(IDDFS)

Graph Cycle :

Topological Sorting :

Minimum Spanning Tree :

BackTracking :

Shortest Paths :

Connectivity :

  1. Find if there is a path between two vertices in a directed graph
  2. Connectivity in a directed graph
  3. Articulation Points (or Cut Vertices) in a Graph
  4. Biconnected Components
  5. Biconnected graph
  6. Bridges in a graph
  7. Eulerian path and circuit
  8. Fleury’s Algorithm for printing Eulerian Path or Circuit
  9. Strongly Connected Components
  10. Transitive closure of a graph
  11. Find the number of islands
  12. Find the number of Islands | Set 2 (Using Disjoint Set)
  13. Count all possible walks from a source to a destination with exactly k edges
  14. Euler Circuit in a Directed Graph
  15. Count the number of non-reachable nodes
  16. Find the Degree of a Particular vertex in a Graph
  17. Check if a given graph is tree or not
  18. Minimum edges required to add to make Euler Circuit
  19. Eulerian Path in undirected graph
  20. Find if there is a path of more than k length
  21. Length of shortest chain to reach the target word
  22. Print all paths from a given source to destination
  23. Find minimum cost to reach destination using train
  24. Find if an array of strings can be chained to form a circle | Set 1
  25. Find if an array of strings can be chained to form a circle | Set 2
  26. Tarjan’s Algorithm to find strongly connected Components
  27. Number of loops of size k starting from a specific node
  28. Paths to travel each nodes using each edge (Seven Bridges of Königsberg)
  29. Number of cyclic elements in an array where we can jump according to value
  30. Number of groups formed in a graph of friends
  31. Minimum cost to connect weighted nodes represented as array
  32. Count single node isolated sub-graphs in a disconnected graph
  33. Calculate number of nodes between two vertices in an acyclic Graph by Disjoint Union method
  34. Dynamic Connectivity | Set 1 (Incremental)
  35. Check if a graph is strongly connected | Set 1 (Kosaraju using DFS)
  36. Check if a given directed graph is strongly connected | Set 2 (Kosaraju using BFS)
  37. Check if removing a given edge disconnects a graph
  38. Find all reachable nodes from every node present in a given set
  39. Connected Components in an undirected graph
  40. k’th heaviest adjacent node in a graph where each vertex has weight

Maximum Flow :

STL Implementation of Algorithms :

Hard Problems :

Misc :

Quick Links :

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. Geeks Classes Live
Get interview-centric live online classes on Data Structure and Algorithms from any geographical location to learn and master DSA concepts for enhancing your problem-solving & programming skills and to crack the interview of any product-based company – Geeks Classes: Live Session

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

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

5. Company Specific Courses – Amazon, Microsoft, TCS & Wipro
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.

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

My Personal Notes arrow_drop_up

Writing code in comment? Please use, generate link and share the link here.