DSAWiser

DSA question set · 168 questions

Graph DSA Practice Questions

Explore 168 DSA questions in Graph. Practice with DSAWiser’s code editor and visualizer.

Graph

What’s in this set

The Graph collection contains 168 problems: 56 basic, 31 easy, 46 medium, 27 hard, 8 very hard. Choose a question at your current level, or follow the collection’s order below.

Topics in this collection include Graph. Each question shows its own topics and difficulty so you can decide where to begin.

Practice with the code visualizer

  1. Open a question in the editor and read the statement, inputs, and expected output. Predict the result for a small example before writing code.
  2. Write a solution and run the examples. If a result differs from your prediction, reduce the input until you can follow each step.
  3. Step through your code in the visualizer. Use a breakpoint to inspect the state at a specific line, then compare it with your reasoning.

Questions in this set

168 total

Open a question in the editor to read its statement and examples. Sign in to practice.

  1. Represent a Graph as an Adjacency MatrixGraphBasic
  2. Represent a Graph as an Adjacency ListGraphBasic
  3. Number of Vertices in an Adjacency MatrixGraphBasic
  4. Count Total Directed Edges from Adjacency MatrixGraphBasic
  5. Count Total Undirected Edges from Adjacency MatrixGraphBasic
  6. Degree of a Vertex in an Undirected Graph (Adjacency Matrix)GraphBasic
  7. In-Degree of a Vertex in a Directed Graph (Adjacency Matrix)GraphBasic
  8. Out-Degree of a Vertex in a Directed Graph (Adjacency Matrix)GraphBasic
  9. Find All Outgoing Neighbors of a Vertex (Adjacency List)GraphBasic
  10. Check if an Edge Exists in an Adjacency MatrixGraphBasic
  11. Convert Adjacency Matrix to Adjacency ListGraphBasic
  12. Convert Adjacency List to Adjacency MatrixGraphBasic
  13. Check for Self-Loops in an Adjacency MatrixGraphBasic
  14. Count Self-Loops in an Adjacency MatrixGraphBasic
  15. Check if a Vertex is IsolatedGraphBasic
  16. Find All Isolated Vertices in an Undirected GraphGraphBasic
  17. Check if a Vertex is a Leaf (Pendant) VertexGraphBasic
  18. Find All Leaf Vertices in an Undirected GraphGraphBasic
  19. Check if a Graph is Undirected (Symmetric Adjacency Matrix)GraphBasic
  20. Check if a Vertex is a Universal VertexGraphBasic
  21. Maximum Degree of a GraphGraphBasic
  22. Minimum Degree of a GraphGraphBasic
  23. Compute Degree Sequence of an Undirected GraphGraphBasic
  24. Sum of Degrees in an Undirected GraphGraphBasic
  25. Verify Handshaking LemmaGraphBasic
  26. Check if a Graph is a Complete GraphGraphBasic
  27. Check if a Graph is an Empty (Null) GraphGraphBasic
  28. Check if a Graph is k-RegularGraphBasic
  29. Check if a Graph is a Regular GraphGraphBasic
  30. Check if a Graph is a Star GraphGraphBasic
  31. Transpose (Reverse) of a Directed Graph (Adjacency Matrix)GraphBasic
  32. Transpose (Reverse) of a Directed Graph (Adjacency List)GraphBasic
  33. Complement of an Undirected GraphGraphBasic
  34. Add an Undirected Edge to an Adjacency MatrixGraphBasic
  35. Remove an Undirected Edge from an Adjacency MatrixGraphBasic
  36. Check if Two Vertices Are Adjacent (Adjacency List)GraphBasic
  37. Find Common Neighbors of Two VerticesGraphBasic
  38. Verify if a Sequence of Vertices is a Valid WalkGraphBasic
  39. Length of a PathGraphBasic
  40. Check Whether a Vertex Sequence Has RepetitionsGraphBasic
  41. Check Whether a Walk Is ClosedGraphBasic
  42. Delete a Vertex from an Adjacency MatrixGraphBasic
  43. Find Destinations of Two-Edge WalksGraphBasic
  44. Count Incoming Neighbors in an Adjacency ListGraphBasic
  45. Check if an Undirected Graph Has an Euler Path Precondition (Degree Parity)GraphBasic
  46. Convert Adjacency Matrix to Edge ListGraphBasic
  47. Check if a Vertex is a Universal Sink in a Directed GraphGraphBasic
  48. Check if a Vertex is a Universal Source in a Directed GraphGraphBasic
  49. Check if Graph Has Any Isolated Connected Component of Size 1GraphBasic
  50. Find All Leaves in a Directed Acyclic Graph (Out-Degree 0 Sinks)GraphBasic
  51. Find All Sources in a Directed Acyclic Graph (In-Degree 0 Sources)GraphBasic
  52. Verify 2-Coloring Assignment in an Undirected GraphGraphBasic
  53. Density of an Undirected Simple GraphGraphBasic
  54. Count Edges in the Complement GraphGraphBasic
  55. Size of Maximum Independent Set in a Star GraphGraphBasic
  56. Deep Copy a Graph Adjacency ListGraphBasic
  57. Find if Path Exists in Undirected GraphGraphEasy
  58. Find the Town JudgeGraphEasy
  59. Find Center of Star GraphGraphEasy
  60. Destination CityGraphEasy
  61. Breadth-First Search (BFS) Traversal OrderGraphEasy
  62. Depth-First Search (DFS) Traversal OrderGraphEasy
  63. Count Connected Components in an Undirected GraphGraphEasy
  64. Size of the Component Containing a Given VertexGraphEasy
  65. Shortest Path in Unweighted Graph (BFS Hop Distance)GraphEasy
  66. Graph Valid Tree CheckGraphEasy
  67. Detect Cycle in an Undirected GraphGraphEasy
  68. Find the Unique Vertex with In-Degree ZeroGraphEasy
  69. Minimum Number of Vertices to Reach All NodesGraphEasy
  70. Flood Fill (Grid Graph)GraphEasy
  71. Island PerimeterGraphEasy
  72. Verify Valid Topological Sort OrderGraphEasy
  73. Maximum Degree of a Node in Connected ComponentGraphEasy
  74. BFS Level Order of VerticesGraphEasy
  75. Check if an Edge is a Bridge (Cut-Edge)GraphEasy
  76. Check if a Vertex is an Articulation Point (Cut-Vertex)GraphEasy
  77. Eccentricity of a Vertex in an Unweighted Connected GraphGraphEasy
  78. Check if Directed Graph is Weakly ConnectedGraphEasy
  79. Count Nodes Reachable from Source in Directed GraphGraphEasy
  80. Check if All Nodes Can Reach a Target VertexGraphEasy
  81. Count Triangles in an Undirected GraphGraphEasy
  82. Reconstruct Shortest Path Sequence (BFS Path)GraphEasy
  83. Check if Undirected Graph Has an Eulerian Circuit PreconditionGraphEasy
  84. Check Graph Isomorphism on 3-Vertex GraphsGraphEasy
  85. Check if an Undirected Graph is a Path GraphGraphEasy
  86. Check if an Undirected Graph is a Cycle GraphGraphEasy
  87. Vertices at Distance K in a TreeGraphEasy
  88. Course Schedule (Cycle Detection in Directed Graph)GraphMedium
  89. Course Schedule II (Topological Sort)GraphMedium
  90. Shortest Paths with Binary Edge Weights (0–1 BFS)GraphMedium
  91. Redundant Connection in Undirected GraphGraphMedium
  92. Evaluate DivisionGraphMedium
  93. Find Eventual Safe StatesGraphMedium
  94. Network Delay Time (Dijkstra's Shortest Path)GraphMedium
  95. Cheapest Flights Within K StopsGraphMedium
  96. Path with Minimum EffortGraphMedium
  97. Pacific Atlantic Water FlowGraphMedium
  98. Rotting OrangesGraphMedium
  99. 01 Matrix (Distance to Nearest Zero)GraphMedium
  100. Shortest BridgeGraphMedium
  101. Surrounded RegionsGraphMedium
  102. Accounts MergeGraphMedium
  103. Number of Operations to Make Network ConnectedGraphMedium
  104. Min Cost to Connect All Points (Minimum Spanning Tree)GraphMedium
  105. Possible Bipartition (Graph 2-Coloring with Dislikes)GraphMedium
  106. Shortest Path with Alternating ColorsGraphMedium
  107. Open the Lock (State-Space Graph BFS)GraphMedium
  108. As Far from Land as PossibleGraphMedium
  109. Shortest Path in Binary MatrixGraphMedium
  110. Number of Strongly Connected Components (Kosaraju's Algorithm)GraphMedium
  111. Parallel Courses (Kahn's Topological Sort with Semesters)GraphMedium
  112. Minimum Fuel Cost to Report to the CapitalGraphMedium
  113. Find the City With the Smallest Number of Neighbors at a Threshold DistanceGraphMedium
  114. Minimum Genetic Mutation (Gene Graph BFS)GraphMedium
  115. Keys and RoomsGraphMedium
  116. Is Graph Bipartite (2-Colorable)GraphMedium
  117. Number of IslandsGraphMedium
  118. Max Area of IslandGraphMedium
  119. Reorder Routes to Make All Paths Lead to City ZeroGraphMedium
  120. All Paths From Source to Target in a DAGGraphMedium
  121. Number of ProvincesGraphMedium
  122. Diameter of an Unweighted Tree GraphGraphMedium
  123. Radius of an Unweighted Tree GraphGraphMedium
  124. Find Center of an Unweighted TreeGraphMedium
  125. Shortest Paths with Negative Edges (Bellman–Ford)GraphMedium
  126. Smallest Subgraph Containing All Marked NodesGraphMedium
  127. Transitive Closure Matrix of a Directed GraphGraphMedium
  128. Check if Graph is a Complete Bipartite GraphGraphMedium
  129. Check if Directed Graph is Strongly ConnectedGraphMedium
  130. Count Crossing Edges After ContractionsGraphMedium
  131. All-Pairs Shortest Distances (Floyd–Warshall)GraphMedium
  132. Longest Distances and Path Counts in a DAGGraphMedium
  133. Minimum Spanning Tree Weight in a Weighted GraphGraphMedium
  134. Redundant Connection IIGraphHard
  135. Shortest Path Visiting All NodesGraphHard
  136. Word Ladder IIGraphHard
  137. Bus RoutesGraphHard
  138. Swim in Rising WaterGraphHard
  139. Maximum Employees to Be Invited to a Meeting (Functional Graph)GraphHard
  140. Find Critical and Pseudo-Critical Edges in Minimum Spanning TreeGraphHard
  141. Reachable Nodes in Subdivided GraphGraphHard
  142. Minimum Number of Days to Disconnect IslandGraphHard
  143. Trapping Rain Water II (2D Elevation Grid)GraphHard
  144. Cut Off Trees for Golf EventGraphHard
  145. Count Visited Nodes in a Directed GraphGraphHard
  146. Maximum Number of Non-Overlapping Substrings (Character Dependencies)GraphHard
  147. Minimum Cost to Reach Destination in TimeGraphHard
  148. Maximum Bipartite Matching (Augmenting Paths)GraphHard
  149. Valid Arrangement of Pairs (Eulerian Path)GraphHard
  150. Satisfiability of 2-SAT (Implication Graph)GraphHard
  151. Number of Increasing Paths in a GridGraphHard
  152. Sort Items by Groups Respecting DependenciesGraphHard
  153. Escape a Large MazeGraphHard
  154. Word Ladder (Shortest Transformation Sequence)GraphHard
  155. Reconstruct Itinerary (Hierholzer's Algorithm)GraphHard
  156. Critical Connections in a Network (Tarjan's Bridge Algorithm)GraphHard
  157. Find All Articulation Points in an Undirected Connected GraphGraphHard
  158. Alien Dictionary (Topological Sort)GraphHard
  159. Frog Position After T SecondsGraphHard
  160. Dinic's Maximum Flow Algorithm on Directed NetworkGraphHard
  161. Global Minimum Cut via Stoer-Wagner AlgorithmGraphVery hard
  162. Edmonds' Blossom Algorithm for General Maximum MatchingGraphVery hard
  163. Dominator Tree of a Flow Graph (Lengauer-Tarjan Algorithm)GraphVery hard
  164. Minimum Cost Maximum FlowGraphVery hard
  165. Planarity Testing of a Simple GraphGraphVery hard
  166. Dynamic Graph Connectivity via Offline DSU with RollbackGraphVery hard
  167. Directed Chinese Postman Problem (Min-Cost Eulerian Tour)GraphVery hard
  168. Tutte Matrix and Random Perfect Matching VerificationGraphVery hard