InterviewStack.io LogoInterviewStack.io

Trees and Graphs Questions

Comprehensive knowledge of tree and graph data structures and algorithms commonly tested in coding interviews. Candidates should understand representations such as adjacency list and adjacency matrix and when to use each, and tree representations including n ary trees and binary search trees. Expect to implement and reason about traversals including depth first search and breadth first search, tree traversals such as pre order in order and post order, and level order traversal. Cover algorithms including topological sorting for directed acyclic graphs, cycle detection, connected components, shortest path algorithms such as breadth first search for unweighted graphs, Dijkstra for nonnegative weights, and Bellman Ford for graphs with negative edges, and minimum spanning tree algorithms such as Kruskal and Prim. Include disjoint set union find for connectivity and for use with Kruskal, lowest common ancestor techniques and implementations, tree dynamic programming problems, serialization and deserialization, reconstruction from traversals, balancing and validation checks for binary search trees and balanced tree concepts, diameter and path sum problems, and common interview patterns such as path finding dependency resolution and structural transformation. Emphasize implementation details and common pitfalls including correct use of visited tracking recursion depth edge cases and disconnected components, and practice articulating time and space complexity tradeoffs and algorithm selection under different constraints.

MediumTechnical
0 practiced
Given two rooted trees (n-ary), determine whether they are isomorphic (structurally identical) considering ordered children. Implement a function in your chosen language for the ordered case and explain how the unordered case is more complex and can be solved via canonical forms (AHU algorithm).
MediumTechnical
0 practiced
Implement topological sort for a directed acyclic graph using Kahn's algorithm (in-degree queue) and also describe a DFS-based postorder approach. Explain how each detects cycles and discuss returning lexicographically smallest topological ordering if node ids are integers.
EasyTechnical
0 practiced
Compare AVL and Red-Black balanced binary search trees. As a software engineer, explain the balancing invariants, rotation operations, height guarantees, insertion/deletion complexity, and practical trade-offs (e.g., stricter balance vs fewer rotations, library choices).
EasyTechnical
0 practiced
Write a function that returns level-order traversal of a binary tree as a list of lists, where each inner list contains the values at that level (top to bottom). Implement in Python or Java, describe node structure, and explain how you handle empty trees and large breadth (memory concerns).
MediumTechnical
0 practiced
Given a binary tree and a target sum, implement a function that returns all root-to-leaf paths where the sum of node values equals the target. Provide a recursive backtracking implementation, explain pruning, and discuss memory usage when many paths exist.

Unlock Full Question Bank

Get access to hundreds of Trees and Graphs interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.