Skip to content

Conversation

Copy link

Copilot AI commented Oct 1, 2025

Overview

This PR adds a comprehensive collection of graph algorithm interview questions to the repository, following the request to "add 10 graph interview and answer with 2 approach for each questions".

Changes

Created a new file graphProblems.js containing 10 common graph algorithm problems, each implemented with 2 different approaches to demonstrate alternative problem-solving techniques.

Graph Problems Included

  1. Depth First Search (DFS) - Recursive and Iterative (Stack-based) implementations
  2. Breadth First Search (BFS) - Queue-based and Level-order traversal approaches
  3. Detect Cycle in Directed Graph - DFS with recursion stack and Color-based detection (White/Gray/Black)
  4. Detect Cycle in Undirected Graph - DFS with parent tracking and Union-Find (Disjoint Set)
  5. Shortest Path (Dijkstra's Algorithm) - Priority Queue implementation and Array-based approach
  6. Topological Sort - DFS-based and Kahn's Algorithm (BFS-based)
  7. Find All Paths Between Two Nodes - DFS with path tracking and Backtracking with visited set
  8. Check if Graph is Bipartite - BFS-based coloring and DFS-based coloring
  9. Number of Connected Components - DFS-based counting and Union-Find
  10. Clone a Graph - DFS-based cloning and BFS-based cloning

Code Quality

  • ✅ All implementations include clear comments explaining the approach
  • ✅ Test cases provided for each problem (commented out to avoid console noise)
  • ✅ Follows the existing repository coding style and patterns
  • ✅ Syntax validated with Node.js
  • ✅ Ready to use in both browser and Node.js environments
  • ✅ Total of 633 lines of production-ready code

Usage

The new graph problems can be used by:

  1. Opening index.html in a browser (script is auto-included)
  2. Uncommenting the test console.log statements to see results
  3. Calling functions directly from the browser console or in Node.js

Example:

const graph = {
    0: [1, 2],
    1: [3, 4],
    2: [5],
    3: [],
    4: [],
    5: []
};

// Use either approach
console.log(dfsRecursive(graph, 0));  // Approach 1
console.log(dfsIterative(graph, 0));  // Approach 2

This addition complements the existing array, string, number, and object problem sets in the repository.

Original prompt

add 10 graph interview and answer with 2 approach for each questions


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] add 10 graph interview and answer with 2 approach for each questions Add 10 graph interview questions with 2 approaches each Oct 1, 2025
Copilot AI requested a review from iamitesh October 1, 2025 20:58
Copilot finished work on behalf of iamitesh October 1, 2025 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants