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.

HardTechnical
59 practiced

A BST is too large for memory and lives on disk. How would you find the kth smallest element, or iterate in order, with as few disk reads as possible and only a few megabytes of memory? Say what metadata you would store.

MediumTechnical
54 practiced

Check whether a binary tree is height-balanced without using recursion. Emulate a postorder walk with an explicit stack, work out how you know each node's children have been finished, and explain how you carry heights and detect the first imbalance. State the time and space cost.

MediumTechnical
47 practiced

Return the maximum width of a binary tree, meaning the largest number of nodes on any one level. Explain how the answer differs for a skewed tree versus a complete tree, and what the queue holds at its peak.

MediumTechnical
51 practiced

Invert a binary tree by swapping the left and right children of every node. Do it recursively and iteratively, and say which you would ship when trees can be very deep.

EasyTechnical
58 practiced

Why does an inorder traversal of a binary search tree come out sorted? State the invariant, argue it by induction on the subtrees, and say what changes when duplicate keys are allowed.

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.