Back to Practice Dashboard
DSA SectionMedium

B Tree

Learn how to solve the 'B Tree' problem. This detailed resource details brute force and optimized approaches.

Problem Statement

Medium

Write a function is_valid_btree_leaf_depth(keys, child_pointers, t) that checks if a B-Tree structure node properties are valid. Specifically, return True if all leaf nodes are at the same depth and every node (except root) has between t-1 and 2t-1 keys, where t is the minimum degree. Input format: keys mapping node ID to list of keys, child_pointers mapping node ID to list of child IDs, and minimum degree t.

Constraints
  • 2 <= t <= 10
  • 1 <= len(keys) <= 100

Examples

Example 1
Input
keys = {1: [10, 20], 2: [5], 3: [15], 4: [25, 30]}, child_pointers = {1: [2, 3, 4]}, t = 2
Output
True
Explanation

Root 1 has keys [10, 20]. Children 2, 3, 4 are leaves at the same depth 1 and satisfy the key count constraint of 1 to 3 keys.

Need a Hint?
Perform a recursive tree traversal (DFS) or level-order traversal (BFS) using a queue/stack.
Edge Cases to Watch
  • Empty list or null input variables
  • Single item lists/arrays
  • Extremely large input bounds causing integer or stack overflow

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor