Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 03 · DSA · Worked, and deeper · about 21 min to read

Play it as a journeyTutor comes with a plan

Trees, asked five ways

Trees
Trees · Open board

Six numbers in a chart: 8 at the top, 3 and 10 under it, then 1, 6 and 14. This lesson asks that one small tree five different questions.

Before you start. A binary search tree is a chart of boxes (nodes) where each box has at most two boxes below it, every smaller number sits somewhere down its left side and every bigger one down its right; Trees (BST, balancing, heaps, tries) built it, and Trees, Worked (rotations, B-trees, range trees) showed how it is kept short. You also need a function that calls itself on a smaller copy of the problem and waits for the answer, which is all recursion is (Recursion & Dynamic Programming).

Lesson 24 of 96 in DSA

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • April 2001: a tree that had to travel as one line
  • Question one: is the filing rule kept? A range carried down
  • Question two: the lowest common ancestor, found by reports sent up
  • Question three: level order, a floor number carried down
  • Question four: rebuild from preorder and inorder, both ways at once
  • Question five: serialize, the tree as one line and back
  • The one question to ask first
  • Measured: how often the neighbour check is fooled
  • The depth trap
  • First time in an interview: the path

Terms it explains: lowest common ancestor, level order, preorder, inorder, serialize, B-tree, balanced, binary tree, BST, complete tree, heap, height h, priority queue, rotation, self-balancing BST (AVL / red-black), sift up/down, traversal, tree, trie.

Review DSA