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.

EasyTechnical
0 practiced
Write an iterative search function in Python to check whether a value exists in a binary search tree (BST). Your function should take the root and the target value and return True/False. Aim for O(h) average time and O(1) auxiliary space. Discuss how the runtime degrades for degenerate trees.
EasyTechnical
0 practiced
What is an in-order successor of a node in a BST? Provide the definition and describe two algorithms to find the in-order successor of a given node: one that assumes parent pointers exist and one that only has access to the tree root and target value. Discuss complexity.
MediumTechnical
0 practiced
Implement deletion of a node in a BST in Python. Your function should correctly handle the three deletion cases: leaf, node with one child, and node with two children (replace with inorder successor or predecessor). Provide O(h) expected time and explain how deletion can affect balance.
EasyTechnical
0 practiced
Explain the worst-case time complexity of basic BST operations (search/insert/delete) when the tree is degenerate (like a linked list). Then list and briefly describe three practical strategies to avoid or mitigate degenerate trees in production ML code.
HardTechnical
0 practiced
Prove that an inorder traversal of a binary search tree yields elements in non-decreasing (sorted) order. Include assumptions about duplicate handling and comparator consistency and explain how the proof changes when duplicates are allowed only on one side.

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.