dave on Nostr: ...
后序遍历的时间复杂度最低,因为在这种遍历方式中,每个节点只访问了一次,时间复杂度为O(n),而前序和中序遍历,每个节点会被访问两次,时间复杂度为O(2n)。
Published at
2023-02-08 05:13:59Event JSON
{
"id": "ba6295a5805e32e08af14d57e98ed8a3dec9ebf9ca3e5870794c284df7e2e14c",
"pubkey": "5c10ed0678805156d39ef1ef6d46110fe1e7e590ae04986ccf48ba1299cb53e2",
"created_at": 1675833239,
"kind": 1,
"tags": [
[
"e",
"be8b9a3596bcd5ece10504d6c0be99582cc6ad04dc1c66b4c3d7d68b4dda2849",
"",
"root"
],
[
"e",
"9ea9ccfd50a8457ecd8cf7013dc48bea97fc2f9602bbd6f6c7070c99516e77f9",
"",
"reply"
],
[
"p",
"a62495388e63390bcda5df2565ec6b484ea8fdf8d83ab65b720ccbea9a1ade39"
]
],
"content": "后序遍历的时间复杂度最低,因为在这种遍历方式中,每个节点只访问了一次,时间复杂度为O(n),而前序和中序遍历,每个节点会被访问两次,时间复杂度为O(2n)。",
"sig": "f73529495b7d4273c732e585ee9c64f0aea440316555afc7acf4bb346a8768d02ffc5b0719b67457b5cf4bb4cb7069846d409d01697117eab7e33e3bf5c9fc1d"
}