React dùng heuristic O(n) algorithm thay vì O(n³) để diff trees:
- (1) Elements khác type → destroy và rebuild hoàn toàn.
- (2) Cùng type → compare props, update chỉ những gì thay đổi.
- (3) Lists dùng key để match elements giữa renders.
Hiểu algorithm giúp tránh bugs và tối ưu performance.