Skip to content
CodeItRaw
Path

Node by node with recursion: sums, depth, paths and search trees.

Key ideas

  • A tree function is usually: base case on None, otherwise combine the left and right results.
  • Every .left / .right is a read. Visiting each node once is O(n).
  • In a search tree (BST), smaller values are on the left, larger on the right: you can skip half without visiting it.

Pattern

def go(node):
    if node is None:
        return empty_answer
    left = go(node.left)
    right = go(node.right)
    return combine(node.val, left, right)

Finish these first:Stacks & Queues

Lessons

Each lesson explains one idea from zero and ends with a few tasks. Lessons open in order; the explanation can be read at any time.

  1. 01

    Node, left, right

    0/2 tasks

  2. 02

    Gathering the answer from the children

    0/3 tasks

  3. 03

    Carrying information down

    0/3 tasks

Boss

  • 04

    Diameter

    Function

  • The boss opens when every lesson of the topic is finished. Solve it too and the topic is complete, and the topics after it open.