Trees and Binary Search Trees Interview Questions for Data Structures and Algorithms
25 Trees and Binary Search Trees questions with answers for data structures and algorithms roles — 7 easy, 13 medium, 5 hard.
About Trees and Binary Search Trees
Learn binary tree terminology and traversals, binary search trees, balanced trees such as AVL and red-black trees, tries, segment trees and Fenwick trees. Practise recursion-based patterns such as height, diameter, lowest common ancestor and validation, and see how B-trees power database indexes and tries power autocomplete.
What are inorder, preorder, postorder and level order traversals?
Show answer
What is a binary search tree and what is its time complexity?
Show answer
What is the difference between full, complete and perfect binary trees?
Show answer
Write an iterative inorder traversal of a binary tree.
Show answer
Find the maximum depth of a binary tree.
Show answer
Tell me about the project you are most proud of.
Show answer
Compare AVL trees and red-black trees.
Show answer
What is a trie and where is it used?
Show answer
How do you find the lowest common ancestor in a BST versus in a general binary tree?
Show answer
How do DFS and BFS differ in memory use on a tree?
Show answer
What is the diameter of a binary tree and how do you compute it efficiently?
Show answer
You must build autocomplete for a search box over one million product names. Which data structure would you use?
Show answer
An application needs sorted data with frequent inserts, deletes and range queries such as all orders between two timestamps. Which structure fits?
Show answer
A teammate's BST validation only checks that each node is greater than its left child and smaller than its right child. Why is that wrong?
Show answer
In a company org chart stored as a tree, how would you find the closest common manager of two employees?
Show answer
Print the level order traversal of a binary tree, one list per level.
Show answer
Write a function to validate a binary search tree.
Show answer
Find the lowest common ancestor of two nodes in a binary tree.
Show answer
Tell me about an interview or exam you failed and what you learned.
Show answer
Compare segment trees and Fenwick trees.
Show answer
What is a B-tree and why do databases use it for indexes?
Show answer
A recursive tree traversal crashes on a skewed tree with one million nodes. How do you fix it?
Show answer
A game leaderboard with millions of players needs fast score updates and queries like what rank is this player. How would you design it?
Show answer
Serialize a binary tree to a string and deserialize it back.
Show answer
Frequently asked questions
How important is Trees and Binary Search Trees in Data Structures and Algorithms interviews?
Learn binary tree terminology and traversals, binary search trees, balanced trees such as AVL and red-black trees, tries, segment trees and Fenwick trees. Practise recursion-based patterns such as height, diameter, lowest common ancestor and validation, and see how B-trees power database indexes and tries power autocomplete.
How should I use the Trees and Binary Search Trees sheet?
Go top to bottom — easy to hard. Answer before opening each answer, tick what you solved and save misses to Last-Minute Revision.