[問題] 多個set作交集
看板Prob_Solve (計算數學 Problem Solving)作者chunhsiang (= =)時間12年前 (2012/10/02 22:19)推噓2(2推 0噓 7→)留言9則, 4人參與討論串1/3 (看更多)
有n的不同大小的set
t1,t2,...,tn
將其n個set全部交集(這裡用and當運算符號)起來
t1 and t2 and ... and tn
請問如何做效率能最好?
比如
A = {1, 2, 3}
B = {2, 3}
C = {1, 2}
D = {2}
(A and B) and (C and D)
= {2, 3} and {2}
= {2}
(((A and D) and B) and C
= (({2} and B) and C)
= {2} and C
= {2}
有不同的運算順序
假設集合A與B作交集 n=|A| m=|B|
只需要O(n+m)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.160.240.173
→
10/02 22:21, , 1F
10/02 22:21, 1F
→
10/02 22:32, , 2F
10/02 22:32, 2F
→
10/02 22:32, , 3F
10/02 22:32, 3F
→
10/02 22:33, , 4F
10/02 22:33, 4F
→
10/02 22:36, , 5F
10/02 22:36, 5F
※ 編輯: chunhsiang 來自: 118.160.240.173 (10/02 22:36)
推
10/02 22:54, , 6F
10/02 22:54, 6F
→
10/02 22:59, , 7F
10/02 22:59, 7F
推
10/02 23:00, , 8F
10/02 23:00, 8F
→
10/12 05:18, , 9F
10/12 05:18, 9F
討論串 (同標題文章)
Prob_Solve 近期熱門文章
PTT數位生活區 即時熱門文章