[問題] 請問path compression

看板C_and_CPP (C/C++)作者 (魯)時間16年前 (2010/03/10 01:13), 編輯推噓2(202)
留言4則, 1人參與, 最新討論串1/1
小弟是data structure初學者... 想請問path compression的定義 書上是這麼寫的 "We can make paths in the trees even shorter by simply making all the objects that we touch point to the root of the new tree for the union operation." 那如果 我今天的tree大概長這樣 0 5 ^ | 1 3 6 | | 2 4 0,5是root 那如果 我對(2,6)做union operation 新的tree應該變怎樣 是 A) 0 B) 0 C) 0 5 ^ ^ ^ 1 2 3 5 6 1 2 3 5 1 2 3 6 | | | | 4 4 6 4 哪一種?? 謝了... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.233.41.22

03/10 01:23, , 1F
(B)這句話在說 : 把找根所經過的節點, 直接接到根上面
03/10 01:23, 1F

03/10 01:24, , 2F
你找 2所屬集合時, 經過了2、1兩個點, 所以他們都要直
03/10 01:24, 2F

03/10 01:25, , 3F
接接到根節點0的下方
03/10 01:25, 3F

03/10 01:30, , 4F
這個google一下就有了說 : 路徑壓縮
03/10 01:30, 4F
文章代碼(AID): #1Bbe6c32 (C_and_CPP)
文章代碼(AID): #1Bbe6c32 (C_and_CPP)