PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Software Engineering Fundamentals/Sig

Trees and Binary Search Trees: Taxonomy, Invariant, and Traversal/Search

Last updated: Jul 1, 2026

Quick Overview

This question evaluates a candidate's grasp of tree data structures and the binary search tree ordering invariant, along with the ability to implement traversal and search operations. It is a common software engineering fundamentals topic used to check whether someone can precisely define an invariant, write correct code, and reason about time and space complexity relative to tree shape.

  • medium
  • Sig
  • Software Engineering Fundamentals
  • Software Engineer

Trees and Binary Search Trees: Taxonomy, Invariant, and Traversal/Search

Company: Sig

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Onsite

This is a fundamentals discussion with a small coding component. Walk an interviewer through trees as a data-structure family, then zoom into binary search trees: 1. **Survey the common kinds of trees** and, for each, give a realistic use case (where it actually shows up in systems). 2. **Define a binary search tree (BST) precisely** — state its ordering invariant exactly, not just "left is smaller." 3. **Implement two operations on a BST**: (a) an in-order traversal that prints keys in sorted order, and (b) a search that returns whether a key is present. State the time and space complexity of each, and how complexity depends on the tree's shape. ```hint Organize the zoo Group trees by their defining property rather than listing them randomly: general vs. binary by branching factor; search-ordered (BST, AVL, red-black); heap-ordered (binary heap); multi-way on-disk (B-tree / B+-tree); and prefix/string (trie). Anchor each to one concrete use. ``` ```hint State the BST invariant exactly The invariant is recursive and applies to whole subtrees, not just immediate children: for every node `x`, every key in `x`'s left subtree is `< x.key` and every key in `x`'s right subtree is `> x.key`. That single property is what makes search and ordered iteration work in `O(height)` / sorted order. ``` ```hint Traversal and search In-order = visit left subtree, then the node, then the right subtree; for a BST that emits keys ascending. Search compares the target to the current node and walks left or right. A full traversal is `O(n)`; a search costs `O(height)`. ``` ### Constraints & Assumptions - Focus on conceptual clarity plus correct, idiomatic code (C++ or clear pseudocode is fine). - Treat the BST as unbalanced unless balancing is explicitly requested, but be ready to discuss balancing as a tradeoff. - Keys are comparable and, unless stated otherwise, unique. ### Clarifying Questions to Ask - Should I assume the BST is balanced, or do you want me to address the worst-case skew (degenerate-to-a-list) and how balancing fixes it? - Are duplicate keys allowed? If so, which subtree convention should they follow (e.g. duplicates go right)? - For the traversal, do you want recursion, or an iterative/`O(1)`-extra-space version (explicit stack / Morris traversal)? - Is the tree read-only for this question, or are insert/delete also in scope? ### What a Strong Answer Covers ```premium-lock What a Strong Answer Covers ``` ### Follow-up Questions - How do AVL trees and red-black trees keep operations `O(log n)`, and what is the cost/benefit difference between them (rotation frequency vs. lookup speed)? - Why do databases and filesystems favor B-trees / B+-trees over binary BSTs for on-disk indexes? - How would you verify in `O(n)` that an arbitrary binary tree is a valid BST? (What's the subtle bug in checking only parent-vs-child?) - When is a hash table a strictly better choice than a BST, and when is the BST's ordering property essential (so a hash table cannot replace it)?

Quick Answer: This question evaluates a candidate's grasp of tree data structures and the binary search tree ordering invariant, along with the ability to implement traversal and search operations. It is a common software engineering fundamentals topic used to check whether someone can precisely define an invariant, write correct code, and reason about time and space complexity relative to tree shape.

Related Interview Questions

  • Implement a Simplified std::vector with Manual Memory Management - Sig (medium)
  • Find and Fix C++ Ownership Bugs: Double Free, Shallow Copy, and Object Slicing - Sig (medium)
|Home/Software Engineering Fundamentals/Sig

Trees and Binary Search Trees: Taxonomy, Invariant, and Traversal/Search

Sig logo
Sig
Jun 15, 2026, 12:00 AM
mediumSoftware EngineerOnsiteSoftware Engineering Fundamentals
0
0

This is a fundamentals discussion with a small coding component. Walk an interviewer through trees as a data-structure family, then zoom into binary search trees:

  1. Survey the common kinds of trees and, for each, give a realistic use case (where it actually shows up in systems).
  2. Define a binary search tree (BST) precisely — state its ordering invariant exactly, not just "left is smaller."
  3. Implement two operations on a BST : (a) an in-order traversal that prints keys in sorted order, and (b) a search that returns whether a key is present. State the time and space complexity of each, and how complexity depends on the tree's shape.

Constraints & Assumptions

  • Focus on conceptual clarity plus correct, idiomatic code (C++ or clear pseudocode is fine).
  • Treat the BST as unbalanced unless balancing is explicitly requested, but be ready to discuss balancing as a tradeoff.
  • Keys are comparable and, unless stated otherwise, unique.

Clarifying Questions to Ask

  • Should I assume the BST is balanced, or do you want me to address the worst-case skew (degenerate-to-a-list) and how balancing fixes it?
  • Are duplicate keys allowed? If so, which subtree convention should they follow (e.g. duplicates go right)?
  • For the traversal, do you want recursion, or an iterative/ O(1) -extra-space version (explicit stack / Morris traversal)?
  • Is the tree read-only for this question, or are insert/delete also in scope?

What a Strong Answer Covers Premium

Follow-up Questions

  • How do AVL trees and red-black trees keep operations O(log n) , and what is the cost/benefit difference between them (rotation frequency vs. lookup speed)?
  • Why do databases and filesystems favor B-trees / B+-trees over binary BSTs for on-disk indexes?
  • How would you verify in O(n) that an arbitrary binary tree is a valid BST? (What's the subtle bug in checking only parent-vs-child?)
  • When is a hash table a strictly better choice than a BST, and when is the BST's ordering property essential (so a hash table cannot replace it)?
Loading comments...

Browse More Questions

More Software Engineering Fundamentals•More Sig•More Software Engineer•Sig Software Engineer•Sig Software Engineering Fundamentals•Software Engineer Software Engineering Fundamentals

Write your answer

Your first approved answer each day earns 20 XP.

Sign in to write your answer.
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.