Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Linked Lists and Trees (Summary)

You’ve practiced the problems where the data is made of references:

  • Linked lists trade instant access by position for cheap relinking. You walked them node by node, reversed one in place, removed a node counted from the end, and sent two runners at different speeds to find a middle or a loop with O(1) extra space.
  • Recursion solves a problem by trusting a smaller call. It’s clear and often the best first answer, but every pending call holds a stack frame, and V8 throws a RangeError once the stack runs out, often after just ten thousand or so frames.
  • Trees let each subtree report back a count, a depth, or a verdict. When the question is about rows, you go level by level. When the tree can be deeper than the call stack allows, you keep your own stack in an array.

Things to Remember in an Interview

  • Draw the boxes and arrows for a small example before you write code, and redraw them after every reassignment.
  • Compare nodes with ===. Two objects with the same data are still two different nodes.
  • End lists with null on purpose, and set the next of a node you remove to null as well.
  • Read optional children with ?? [], and ask how deep and how wide the input can get before you choose recursion.
  • Remember that { ...node } copies one level. Use structuredClone() or copy each level yourself when you need an independent tree.

Keep Practicing

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.