InterviewStack.io LogoInterviewStack.io

Binary Trees and Binary Search Trees Questions

Focuses on tree data structures, specifically binary trees and binary search trees. Candidates should understand node relationships, common traversals including in order, pre order, post order, and level order, and be able to implement traversals both recursively and iteratively. Cover binary search tree properties and operations including search, insertion, deletion, validation of binary search tree property, and finding the lowest common ancestor. Include problems on tree paths, height and balance calculations, serialization and deserialization, checking and restoring balance at a high level, and use cases in system design. Emphasize complexity analysis, recursion versus iterative solutions using stacks or queues, and handling edge cases such as duplicate keys and degenerate trees.

HardTechnical
53 practiced
Given extremely skewed insertion order (e.g., always increasing keys) that leads to worst-case BST performance, propose algorithms to keep the tree balanced with minimal runtime overhead: randomized balancing (treaps), periodic rebuild from sorted array, or switching to self-balancing trees (AVL/Red-Black). Analyze amortized cost and explain how SRE would implement an automated rehealing job to fix skewed indexes.
HardTechnical
45 practiced
As an SRE you must choose between a BST-backed ordered index and a hash-based index for a new telemetry pipeline. Explain how you would evaluate trade-offs including latency, memory usage, support for range queries, write amplification, operational complexity, and recovery. Present a recommendation for a telemetry pipeline and describe how you would communicate that decision and measure success.
MediumTechnical
56 practiced
Write an O(n) algorithm to detect whether a binary tree is degenerate (i.e., every node has at most one child, so the tree is effectively a linked list). Then outline two methods to rebalance a degenerate BST in production: (1) rebuild the tree from its sorted elements, and (2) apply rotations to produce a balanced tree (e.g., day-stout-warren or AVL rotations). Discuss downtime, computational cost, and which method an SRE might choose under different SLAs.
HardTechnical
49 practiced
Design a serialization format for BST snapshots that includes checksums, version numbers, and a strategy for forward and backward compatibility. Implement a Python function that writes a snapshot file with a checksum and version header and a reader that validates the checksum and either accepts, upgrades, or rejects the file. Discuss performance trade-offs and how SREs can validate snapshots in CI.
HardTechnical
48 practiced
Explain Morris inorder traversal which achieves O(1) extra space by temporarily modifying tree pointers. Walk through the algorithm step-by-step on a small example tree, explain how and when threaded links are added and removed, and discuss the trade-offs for production SRE (pointer mutations during traversal, thread-safety concerns, and debugging complexity).

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.