Algorithms and Data Structures · Senior · Question 35 of 75

Why does React's reconciliation run in O(n) when a general tree diff is about O(n³)?

Explanation

The minimal tree edit distance is expensive. React compares level by level: a changed type replaces the subtree, and key matches children between renders. These heuristics are almost always right for UI code.

Further reading

Problem with a question

Algorithms and Data Structures · Senior · question 35

Test yourself

Take the Algorithms and Data Structures · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz