Processing math: 100%

Algorithm

[기초 알고리즘] 수학: 멱집합

noahkim_ 2024. 2. 25. 16:55

1. 멱집합 (Power Set)

  • 임의의 집합 S에서 모든 부분 집합들로 구성된 집합입니다.
  • P(S)={A:AS}

 

코드

더보기
private void powerset(int depth) {
    if (depth == size) {
        List<String> temp = new ArrayList<>();
        for (int i = 0; i < visited.length; i++) {
            if (!visited[i]) continue;
                
            temp.add(String.valueOf(src[i]));
        }
        
        System.out.println(Arrays.toString(temp));
        return;
    }

    visited[depth] = false;
    powerset(depth+1);
    visited[depth] = true;
    powerset(depth+1);
}

 

{a,b}의 멱집합
  • P({a,b})={,{a},{b},{a,b}}

 

{a,b,c}의 멱집합
  • P({a,b,c})={,{a},{b},{c},{a,b},{a,c},{b,c},{a,b,c}}

 

출처