Trees and Binary Search Trees Questions

Tree data structures as tested in coding interviews: binary trees, binary search trees, self-balancing trees (AVL insertion and deletion with rotations, a comparison with red-black trees, and alternatives such as treaps, splay trees and scapegoat trees), tries (prefix trees and radix trees), and N-ary, size-augmented and sum-augmented trees such as order-statistic trees. Covers traversal orders (in/pre/post-order, level-order, zigzag, iterative, generator-based and Morris variants), BST search, insertion and deletion invariants including duplicate-key policies, validation, successor and iterator design, range and kth-smallest queries, lowest common ancestor (including parent pointers, binary lifting and repeated queries on a static tree), tree reconstruction from traversals, serialization formats and parsing, converting between trees and sorted lists or linked lists, height, balance, diameter and path-sum recursion, subtree equality and hashing, persistent and snapshot-consistent trees, and how tree shape drives logarithmic versus degenerate performance. Excludes plain linked-list and stack/queue exercises with no tree in them, tree dynamic programming recurrences, general graph traversal, heap mechanics, and on-disk database index design, which are covered elsewhere.

EasyTechnical
55 practiced

When would you choose a BST over a hash map or a sorted array? Compare lookup speed, insertion cost, ordered traversal and range queries, and memory.

HardTechnical
46 practiced

Design a persistent (versioned) BST so you can query any past version. Explain path copying, the memory cost per update, how queries start from a version root, and how it compares with copying the whole tree.

HardTechnical
84 practiced

Serialize and deserialize a binary tree with up to ten million nodes in Python, with preorder and null markers. How do you stream the output to disk and read it back without holding every token in memory?

EasyTechnical
57 practiced

How do you validate that a binary tree is a BST? Why is comparing each node only to its immediate children not enough? Compare the min/max range method with the inorder method.

EasyTechnical
51 practiced

What is a degenerate (skewed) BST? How does it arise, what does it do to search, insert and delete, and how do you prevent it?

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.