Tree
Hierarchical nodes — traversals, recursive subtree answers, binary search trees, and construction.
This topic is part of Pro.
Free covers the C and Python courses, the first three DSA topics, the opening system design lessons and the beginner AI lessons, all with the full coach. Pro opens the rest of the library in the FollowtheDamnCode app.
What is in it
- 1Tree basicsNodes, children, depth and height, and the shapes of binary trees that decide how fast they are. Pro
- 2Tree traversalsPreorder, inorder, postorder with recursion or a stack; level order with a queue. Pro
- 3Solving tree problems recursivelyDecide what each call returns about its subtree, combine the children's answers, and track a global best when needed. Pro
- 4Binary search treesLeft is smaller, right is larger — search in O(height), and an inorder walk comes out sorted. Pro
- 5Building and serializing treesRebuild a tree from preorder + inorder, and turn any tree into a string and back. Pro