InterviewStack.io LogoInterviewStack.io

Trees and Binary Search Trees Questions

Hierarchical structures: binary trees, binary search trees, balanced trees, and tries. Covers traversal orders (in/pre/post-order, level-order), insertion and deletion invariants, and using tree properties to achieve logarithmic search. A core mid-difficulty interview area and the basis for many indexing and lookup systems.

HardTechnical
62 practiced

Design a concurrent singly linked list for a high-throughput in-memory queue used by ingestion workers. Discuss lock-based vs lock-free approaches, per-node vs coarse-grained locking, memory reclamation (hazard pointers/epoch), and how you would test for correctness under concurrency.

HardTechnical
48 practiced

Design and implement a compressed prefix tree (radix / PATRICIA trie) in Python that supports insert(word), search(word), and starts_with(prefix). Focus on memory efficiency and speed when storing millions of short strings (e.g., 10M keys). Discuss trade-offs versus a hash table for prefix queries and how to reduce memory overhead in Python.

HardTechnical
62 practiced

Given a binary tree, find the subtree with maximum sum of node values. Implement a Python function that returns the root of the maximum-sum subtree and the sum. Use a single-pass recursion and explain how you avoid recomputing subtree sums.

MediumTechnical
46 practiced

Given a binary tree, implement a level-order traversal function that returns node values grouped by depth (list of lists) using BFS and a queue. Implement in Python and explain how to handle very wide levels (millions of nodes) in terms of memory.

MediumTechnical
42 practiced

Explain how tries (prefix trees) extend the tree concept. For a dataset of textual keys (file paths, topic names), describe memory/compression strategies (radix trees, finite-state transducers), and implement a simple trie insert and prefix-search in Python. Discuss trade-offs for very large alphabets.

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.