Comprehensive mastery of tree and graph traversal algorithms, representations, and common interview problem patterns. Understand graph models and representation choices including adjacency lists versus adjacency matrices and trade offs based on sparsity and density, as well as properties such as directed versus undirected and weighted versus unweighted edges. Know visited state management to avoid cycles and techniques for cycle detection. Implement breadth first search and depth first search in both recursive and iterative forms, understand when to use a queue versus a stack, and analyze time and space complexity. Apply traversals to problems such as shortest path in unweighted graphs, connected component detection, topological sort for dependency ordering, cycle detection, path existence, and island counting. For trees, master traversal orders including in order, pre order, post order, and level order with both recursive and iterative implementations, including explicit stack based approaches and constant space approaches where relevant. Practice tree specific problems such as lowest common ancestor, path sum, tree serialization and deserialization, validating binary search trees, balancing and reconstruction of trees from traversal sequences, and converting between tree and graph formulations. Emphasize clean code, correctness, handling edge cases such as empty or skewed structures, recursion base cases and depth limits, and explaining trade offs between recursion and iterative solutions with respect to performance and memory.
HardSystem Design
34 practiced
Design instrumentation and analytics pipeline that uses graph traversals to detect degradation propagation in a service dependency graph. Requirements: ingest metrics/traces, build time-windowed graph snapshots, compute propagation signals (latency or error impact), surface likely root causes, and allow near-real-time queries for on-call. Discuss ingestion, storage, incremental graph computation, alert heuristics, and cost/accuracy trade-offs.
EasyTechnical
31 practiced
Explain breadth-first search (BFS) and depth-first search (DFS). Describe their algorithmic differences, the typical data structures used (queue vs stack/recursion), and practical SRE scenarios where you'd prefer one over the other (e.g., shortest unweighted path, dependency-depth analysis, reachability checks). Compare their time and space complexity and mention limitations for extremely deep or very wide graphs.
EasyTechnical
35 practiced
Implement iterative inorder traversal of a binary tree in Python. Given class TreeNode with attributes val, left, right, write a function inorder_iterative(root: TreeNode) -> List[int] that returns node values in inorder. Handle empty and skewed trees and aim for O(n) time and O(h) stack space, where h is tree height. Example: root = [1,null,2,3] => [1,3,2].
HardTechnical
28 practiced
You ingest a stream of service call logs (caller->callee, timestamp). During an incident you want to detect anomalous cycles appearing within a sliding time window (e.g., 5 minutes) such as A->B->C->A that are more frequent than baseline. Design a streaming algorithm that detects such transient cycles, describe data structures (time-indexed adjacency), approximations to reduce cost, and provide a prototype sketch for production at scale.
HardTechnical
28 practiced
Implement Tarjan's algorithm in Python to find articulation points (cut vertices) and bridges (cut edges) in an undirected graph. Signature: find_critical_elements(adj: Dict[int,List[int]]) -> (List[int], List[Tuple[int,int]]). Explain discovery times, low-link values, root handling, and complexity. Use for reliability analysis to find single points of failure in service graphs.
Unlock Full Question Bank
Get access to hundreds of Tree and Graph Traversal interview questions and detailed answers.