Curated Tree Exercises

These are all standard problems that sites like LeetCode and CodeWars kindly provide. While of course the first questions are “easiest” in a sense, they’re really the opportunity to learn the core ideas for approaching tree-based problems, and so are best done with instruction. It is after those introductory questions that the “basic” questions can be attempted on their own.

Introductory Questions

I strongly feel these should be done with a teacher, or some other prior instruction on what binary trees are. The distance between their description, and actually applying them, is large. I think these questions are the best we have (so far…) for introducing trees.

Basic Questions

These can be attempted by yourself with instruction.

  • This univalued binary-tree problem is a bit contrived, but a clean-enough example of a tree reduction. It is something of an extension of the binary-search. Solution here.
  • Tree sum is a perfectly good tree-reduction question. Solution here.
  • Tree equality is a nice culminating basic question: we jump from 1 tree to 2 trees, but the “skeleton” remains the same. That we can use the same skeleton can be a tricky insight! Solution here.
  • BST search is also useful.

Intermediate Questions

These questions move beyond the “basic skeleton”, or it isn’t obvious how to use it.

  • BST validation?

Advanced Questions

There are of course plenty of “hard” tree questions, but the thing I want to do is find ones that reflect standard knowledge.