Build tree skills through binary tree traversal and structure, alongside BST search, updates, validation and ordered queries.
Log in/Sign up to track your progress
Striver’s Trees Sheet contains 45 coding questions covering binary trees and binary search trees, or BSTs. It retains the original 44-question selection and adds Requirements needed to construct a unique BT beside the reconstruction questions. The combined sheet contains 31 binary tree and 14 BST exercises, with introductory learning resources kept separate.
The collection covers visiting nodes, combining child results, identifying paths and views, rebuilding structure and answering ordered queries. These tasks need different information. A downward path is different from a complete path between any two nodes, and finding a kth value is different from searching for a key whose numeric value equals k.
Binary tree practice covers traversal, height, balance, paths, views, construction and structural changes. The unique-construction prerequisite belongs with reconstruction because the available traversal information affects whether a tree can be recovered. BST practice then adds its ordering rule for search, updates, validation, ordered queries and subtree analysis.
Use the binary tree introduction before traversal practice and the BST introduction before ordered-tree questions. Know recursion, node references and a missing child; queue-based traversal also needs queue operations. A general binary tree and a BST share a node structure but follow different rules for where values may appear.
A node stores a value and references to its children. The root has no parent, a leaf has no children, and a subtree contains a node and all its descendants. A missing child is different from a node holding zero. Separate nodes can store equal values, so node identity and stored value are not always interchangeable.
An ordinary binary tree has no key-order requirement. Under the usual distinct-key BST rule, every key in a left subtree is smaller and every key in a right subtree is larger, including deeper descendants. Checking only immediate children can miss an ordering violation. If equal keys are allowed, their placement or counting policy must stay consistent.
Let n be the number of nodes and h the number of nodes on the longest root-to-leaf path. Visiting each node a constant number of times takes O(n) time. Standard BST path operations take O(h): logarithmic when height is logarithmic, but linear on a skewed chain. A kth query implemented through inorder traversal may still visit many nodes.
Recursive traversal uses O(h) waiting-call space. Level order stores a frontier whose size depends on the tree’s width, and returned sequences or paths need their own storage. Height and diameter can be measured in nodes or edges; the chosen definition determines the base cases. A longest path between two nodes need not pass through the root.