Validate graph symmetric
Last updated: November 23, 2025
Quick Overview
Given an undirected graph represented as an adjacency matrix, write a function to determine if the graph is symmetric. The function should return `true` if the graph is symmetric (i.e., for every edge from vertex A to vertex B, there is an edge from vertex B to vertex A) and `false` otherwise. The input will be a square matrix of size n x n, where n is the number of vertices in the graph.
Redfin
November 23, 2025453
8
645 solved
Given an undirected graph represented as an adjacency matrix, write a function to determine if the graph is symmetric. The function should return `true` if the graph is symmetric (i.e., for every edge from vertex A to vertex B, there is an edge from vertex B to vertex A) and `false` otherwise. The input will be a square matrix of size n x n, where n is the number of vertices in the graph.
Redfin uses this problem in the Take-home Project to evaluate your algorithmic thinking. They expect you to discuss multiple approaches, analyze trade-offs between them, and implement the optimal solution with clean, readable code.
What the Interviewer Expects
- Recognize the underlying problem pattern (sliding window, two pointers, BFS/DFS, etc.)
- Discuss multiple approaches and trade-offs before coding
- Implement an optimal solution with clean, production-quality code
- Handle all edge cases including boundary conditions and invalid input
- Optimize both time and space complexity with clear justification
- Test your solution systematically with well-chosen examples
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you parallelize this solution?
- Can you optimize the space complexity of your solution?
- What if the input doesn't fit in memory?
- How would you test this solution thoroughly?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Problem Analysis
The problem requires us to check whether an undirected graph is symmetric based on its adjacency matrix representation. A graph is symmetric if for every edge from vertex A to vertex B, there exists a...
Approach
- Input Validation: First, check if the input is a square matrix (n x n). If not, return false.
- Matrix Comparison: Use a nested loop to iterate through the upper triangle of the matrix (...