Graph Data Structure And Algorithms

  • Last Updated :26 Aug, 2022

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

What is Graph in Data Structure and Algorithms?


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.

Basics of Graph:

Topics:

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

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.

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


My Personal Notesarrow_drop_up

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