The time complexity of the traditional diff algorithm mentioned in React is O (n ^ 3)?

The time complexity of the traditional diff algorithm mentioned in

React is O (n ^ 3)?
how does this calculate the amount?

Jul.20,2021

A survey on tree edit distance and related problems

the way React uses is theoretically O (n), because of some restrictions and auxiliary (key).

related: https://reactjs.org/docs/reco.


react trees are compared according to levels. He will give the tree the number 0meme1pl 2p3pl 4. Then compare with the same number. So the complexity is n, which is easy to understand.

the key is how to calculate the complexity of traditional diff? Traditional diff requires cross-level comparisons in addition to the above comparisons. He will compare the
nodes of two numbers, which is the complexity of n ^ 2. Then you need to edit the tree, which can occur at any node, and you need to traverse the tree again, so the complexity is n. It adds up to n ^ 3. I am not involved in the rigorous reasoning process here, just to give you a perceptual understanding. If there are any mistakes, we will not be held responsible.

here is an answer. You can also refer to react

.
how do you calculate O (n ^ 3) and O (n) from O (n ^ 3) to O (n),? -COIN's answer-Zhihu
https://www.zhihu.com/questio..
Menu