Skip to content

Latest commit

ย 

History

History
975 lines (759 loc) ยท 24.4 KB

week_03.md

File metadata and controls

975 lines (759 loc) ยท 24.4 KB

3์ฃผ์ฐจ-์ •๋ ฌ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ตฌํ˜„


์ •๋ ฌ ์•Œ๊ณ ๋ฆฌ์ฆ˜

๋ถ„๋ฅ˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜
๋‹จ์ˆœํ•˜์ง€๋งŒ ๋Š๋ฆผ
O(nยฒ)
๊ฑฐํ’ˆ ์ •๋ ฌ(Bubble Sort)
์‚ฝ์ž… ์ •๋ ฌ(Insertion) Sort)
์„ ํƒ ์ •๋ ฌ(Selection Sort)
๋ณต์žกํ•˜์ง€๋งŒ ๋น ๋ฆ„
O(n log n)
ํ€ต ์ •๋ ฌ(Quick Sort)
ํ•ฉ๋ณ‘ ์ •๋ ฌ(Merge Sort)
ํž™ ์ •๋ ฌ(Heap Sort)
ํ‰๊ท 
O(n)
๋ผ๋”•์Šค ์ •๋ ฌ(Radix Sort)


Java์˜ ์ •๋ ฌ

๊ธฐ๋ณธ ํƒ€์ž… ๋ฐ์ดํ„ฐ์˜ ์ •๋ ฌ

  • Arrays ํด๋ž˜์Šค๋Š” primitive ํƒ€์ž… ๋ฐ์ดํ„ฐ๋ฅผ ์œ„ํ•œ ์ •๋ ฌ ๋ฉ”์„œ๋“œ ์ œ๊ณต
    // ์ •๋ ฌํ•  ๋ฐ์ดํ„ฐ
    int[] data = new int[capacity];
    
    // data[0]์—์„œ data[capacity-1]๊นŒ์ง€ ๋ฐ์ดํ„ฐ๊ฐ€ ๊ฝ‰ ์ฐจ ์žˆ๋Š” ๊ฒฝ์šฐ
    Arrays.sort(data);
    // data[0]์—์„œ data[size-1]๊นŒ์ง€ size๊ฐœ์˜ ๋ฐ์ดํ„ฐ๋งŒ ์žˆ๋Š” ๊ฒฝ์šฐ
    Arrays.sort(data, 0, size);
    • int ์ด์™ธ์˜ ๋‹ค๋ฅธ primitive ํƒ€์ž… ๋ฐ์ดํ„ฐ(double, char)์— ๋Œ€ํ•ด์„œ๋„ ์ œ๊ณต

๊ฐ์ฒด์˜ ์ •๋ ฌ : ๋ฌธ์ž์—ด

  • primitive ํƒ€์ž… ๋ฐ์ดํ„ฐ์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ Arrays.sort ๋ฉ”์„œ๋“œ๋กœ ์ •๋ ฌ
    // ์ •๋ ฌํ•  ๋ฐ์ดํ„ฐ
    String[] fruits = new String[] {"pineapple", "apple", "orange", "banana"};
    
    Arrays.sort(fruits);
    
    for(String name : fruits)
        System.out.println(name);

ArrayList ์ •๋ ฌ : ๋ฌธ์ž์—ด

  • Collections.sort ๋ฉ”์„œ๋“œ๋กœ ์ •๋ ฌ
    // ์ •๋ ฌํ•  ๋ฐ์ดํ„ฐ์˜ ์ €์žฅ๊ณต๊ฐ„
    List<String> fruits = new ArrayList<String>();
    
    // ์ •๋ ฌํ•  ๋ฐ์ดํ„ฐ
    fruits.add("Pineapple");
    fruits.add("Apple");
    fruits.add("Orange");
    fruits.add("Banana");  
    
    Collections.sort(fruits);
    
    for(String name: fruits)
        System.out.println(name);

๊ฐ์ฒด์˜ ์ •๋ ฌ : ์‚ฌ์šฉ์ž ์ •์˜ ๊ฐ์ฒด

์˜ค๋ฅ˜๊ฐ€ ๋‚˜๋Š” ์ •๋ ฌ

// ์‚ฌ์šฉ์ž ์ •์˜ ๊ฐ์ฒด ์ƒ์„ฑ
public class Fruit
{       
    public String name;
    
    public int quantity;
    
    public Fruit(String name, int quantity)
    {
        
        this.name = name;
        
        this.quantity = quantity;
        
    }
}

//====================================================//

// ์‹คํ–‰ ํ…Œ์ŠคํŠธ ํด๋ž˜์Šค
public class test()
{
    public static void main(String[] args)
    {
        Fruit[] fruits = new Fruit[4];
        
        fruits[0] = new Fruit("Pineapple", 70);
        fruits[1] = new Fruit("Apple", 100);
        fruits[2] = new Fruit("Orange", 80);
        fruits[3] = new Fruit("Banana", 90);
        
        Arrays.sort(fruits);
        
    }
}

์˜ค๋ฅ˜๊ฐ€ ๋‚˜์ง€ ์•Š๋Š” ์ •๋ ฌ

  • ์ด๋ฆ„์ˆœ ์ •๋ ฌ

    // ์‚ฌ์šฉ์ž ์ •์˜ ๊ฐ์ฒด ์ƒ์„ฑ
    public class Fruit implements Comparable<Fruit>
    {
        public String name;
        
        public int quantity;
        
        public Fruit(String name, int quantity)
        {
            
            this.name = name;
            
            this.quantity = quantity;
            
        }
        
        @Override
        public int compareTo(Fruit o)
        {
            return name.compareTo(o.name);
        }
        
    }
    
    //====================================================//
    
    // ์‹คํ–‰ ํ…Œ์ŠคํŠธ ํด๋ž˜์Šค, ์œ„์™€ ๋™์ผํ•˜๋ฏ€๋กœ ์ƒ๋žต
  • ์žฌ๊ณ  ์ˆ˜๋Ÿ‰๋ณ„ ์ •๋ ฌ

    // ์‚ฌ์šฉ์ž ์ •์˜ ๊ฐ์ฒด ์ƒ์„ฑ
    public class Fruit implements Comparable<Fruit>
    {
        public String name;
        
        public int quantity;
        
        public Fruit(String name, int quantity)
        {
            
            this.name = name;
            
            this.quantity = quantity;
            
        }
        
        @Override
        public int compareTo(Fruit o)
        {
            return quantity - o.quantity;
        }
        
    }
    
    //====================================================//
    
    // ์‹คํ–‰ ํ…Œ์ŠคํŠธ ํด๋ž˜์Šค, ์œ„์™€ ๋™์ผํ•˜๋ฏ€๋กœ ์ƒ๋žต

ํ•˜๋‚˜์˜ ๊ฐ์ฒด ํƒ€์ž…์— 2๊ฐ€์ง€ ์ด์ƒ์˜ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌ

1. Comparator ํด๋ž˜์Šค extends
2. compare ๋ฉ”์„œ๋“œ๋ฅผ Overrideํ•˜๋Š” ์ƒˆ๋กœ์šด ์ด๋ฆ„ ์—†๋Š” ํด๋ž˜์Šค๋ฅผ ์ •์˜
3. ํ•ด๋‹น ํด๋ž˜์Šค์˜ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

- ๊ทธ๋ ‡๋‹ค๋ฉด Comparator ๊ฐ์ฒด๋“ค์€ ์–ด๋””์— ๋‘˜ ๊ฒƒ์ธ๊ฐ€?
    : ๋ฐ์ดํ„ฐ ๊ฐ์ฒด์˜ static member๋กœ ๋‘”๋‹ค.
    : ์ •๋ ฌ ์‹œ Arrays.sort(fruits, Fruit.xxxComparator); ๋กœ ์‚ฌ์šฉํ•œ๋‹ค.
  • Comparator์˜ ์‚ฌ์šฉ
    public class Fruit
    {
        public String name;
        
        public int quantity;
        
        public Fruit(String name, int quantity)
        {
            
            this.name = name;
            
            this.quantity = quantity;
            
        }
        
        // Comparator์˜ ์ต๋ช… ํด๋ž˜์Šค ์ •์˜ ํ›„ compare ๋ฉ”์„œ๋“œ ์žฌ์ •์˜(์ด๋ฆ„์ˆœ)
        public static Comparator<Fruit> nameComparator = new Comparator<Fruit>() {
            
            @Override
            public int compare(Fruit o1, Fruit o2)
            {
                return o1.name.compareTo(o1.name);
            }
        };
        
        // Comparator์˜ ์ต๋ช… ํด๋ž˜์Šค ์ •์˜ ํ›„ compare ๋ฉ”์„œ๋“œ ์žฌ์ •์˜(์žฌ๊ณ  ์ˆ˜๋Ÿ‰๋ณ„)
        public static Comparator<Fruit> quantityComparator = new Comparator<Fruit>() {
            
            @Override
            public int compare(Fruit o1, Fruit o2)
            {
                return o1.quantity - o2.quantity;
            }
        };
        
    }
    
    //====================================================//
    
    // ์‹คํ–‰ ํ…Œ์ŠคํŠธ ํด๋ž˜์Šค
    public class test()
    {
        public static void main(String[] args)
        {
            Fruit[] fruits = new Fruit[4];
            
            fruits[0] = new Fruit("Pineapple", 70);
            fruits[1] = new Fruit("Apple", 100);
            fruits[2] = new Fruit("Orange", 80);
            fruits[3] = new Fruit("Banana", 90);
            
            Arrays.sort(fruits, nameComparator);
            // OR
            Arrays.sort(fruits, quantityComparator);
        }
    }


C#์˜ ์ •๋ ฌ

๊ธฐ๋ณธ ํƒ€์ž… ๋ฐ์ดํ„ฐ์˜ ์ •๋ ฌ

  • Array ํด๋ž˜์Šค๋Š” primitive ํƒ€์ž… ๋ฐ์ดํ„ฐ๋ฅผ ์œ„ํ•œ ์ •๋ ฌ ๋ฉ”์„œ๋“œ ์ œ๊ณต
    // ์ •๋ ฌํ•  ๋ฐ์ดํ„ฐ
    int[] data = new int[capacity];
    
    // data[0]์—์„œ data[capacity-1]๊นŒ์ง€ ๋ฐ์ดํ„ฐ๊ฐ€ ๊ฝ‰ ์ฐจ ์žˆ๋Š” ๊ฒฝ์šฐ
    Array.Sort(data);
    // data[0]์—์„œ data[size-1]๊นŒ์ง€ size๊ฐœ์˜ ๋ฐ์ดํ„ฐ๋งŒ ์žˆ๋Š” ๊ฒฝ์šฐ
    Array.Sort(data, 0, size);
    • int ์ด์™ธ์˜ ๋‹ค๋ฅธ primitive ํƒ€์ž… ๋ฐ์ดํ„ฐ(double, char)์— ๋Œ€ํ•ด์„œ๋„ ์ œ๊ณต

๊ฐ์ฒด์˜ ์ •๋ ฌ : ๋ฌธ์ž์—ด

  • primitive ํƒ€์ž… ๋ฐ์ดํ„ฐ์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ Array.Sort ๋ฉ”์„œ๋“œ๋กœ ์ •๋ ฌ
    // ์ •๋ ฌํ•  ๋ฐ์ดํ„ฐ
    String[] fruits = new String[] {"pineapple", "apple", "orange", "banana"};
    
    Array.Sort(fruits);
    
    foreach(String name in fruits)
        Console.WriteLine(name);

ArrayList ์ •๋ ฌ : ๋ฌธ์ž์—ด

  • Sort() ๋ฉ”์„œ๋“œ๋กœ ์ •๋ ฌ
    // ์ •๋ ฌํ•  ๋ฐ์ดํ„ฐ์˜ ์ €์žฅ๊ณต๊ฐ„
    ArrayList fruits = new ArrayList();
    
    // ์ •๋ ฌํ•  ๋ฐ์ดํ„ฐ
    fruits.Add("Pineapple");
    fruits.Add("Apple");
    fruits.Add("Orange");
    fruits.Add("Banana");  
    
    fruits.Sort();
    
    foreach(String name in fruits)
        Console.WriteLine(name);

๊ฐ์ฒด์˜ ์ •๋ ฌ : ์‚ฌ์šฉ์ž ์ •์˜ ๊ฐ์ฒด

์˜ค๋ฅ˜๊ฐ€ ๋‚˜๋Š” ์ •๋ ฌ

// ์‚ฌ์šฉ์ž ์ •์˜ ๊ฐ์ฒด ์ƒ์„ฑ
public class Fruit
{       
    public String name;
    public int quantity;

    public Fruit(String name, int quantity)
    {
        this.name = name;
        this.quantity = quantity;
    }
}

//====================================================//

// ์‹คํ–‰ ํ…Œ์ŠคํŠธ ํด๋ž˜์Šค
public class test()
{
    public static void Main(string[] args)
    {
        Fruit[] fruits = new Fruit[4];

        fruits[0] = new Fruit("Pineapple", 70);
        fruits[1] = new Fruit("Apple", 100);
        fruits[2] = new Fruit("Orange", 80);
        fruits[3] = new Fruit("Banana", 90);

        Array.Sort(fruits);

        foreach (Fruit member in fruits)
        {
            Console.WriteLine(member);
        }
    }
}

์˜ค๋ฅ˜๊ฐ€ ๋‚˜์ง€ ์•Š๋Š” ์ •๋ ฌ

  • ์ด๋ฆ„์ˆœ ์ •๋ ฌ

    // ์‚ฌ์šฉ์ž ์ •์˜ ๊ฐ์ฒด ์ƒ์„ฑ, IComparable ๊ตฌํ˜„
    public class Fruit : IComparable<_Fruit>
    {       
        public String name;
        public int quantity;
    
        public Fruit(String name, int quantity)
        {
            this.name = name;
            this.quantity = quantity;
        }
    
        // ์ •๋ ฌ์„ ์œ„ํ•œ ๊ฐ์ฒด ๊ตฌํ˜„
        public int CompareTo(_Fruit o)
        {
            return name.CompareTo(o.name);
        }
    }
    
    //====================================================//
    
    // ์‹คํ–‰ ํ…Œ์ŠคํŠธ ํด๋ž˜์Šค, ์œ„์™€ ๋™์ผํ•˜๋ฏ€๋กœ ์ƒ๋žต
  • ์žฌ๊ณ  ์ˆ˜๋Ÿ‰๋ณ„ ์ •๋ ฌ

    // ์‚ฌ์šฉ์ž ์ •์˜ ๊ฐ์ฒด ์ƒ์„ฑ, IComparable ๊ตฌํ˜„
    public class Fruit : IComparable<_Fruit>
    {       
        public String name;
        public int quantity;
    
        public Fruit(String name, int quantity)
        {
            this.name = name;
            this.quantity = quantity;
        }
    
        // ์ •๋ ฌ์„ ์œ„ํ•œ ๊ฐ์ฒด ๊ตฌํ˜„
        public int CompareTo(_Fruit o1, _Fruit o2)
        {
            return o1.quantity - o2.quantity;
        }
    }
    
    //====================================================//
    
    // ์‹คํ–‰ ํ…Œ์ŠคํŠธ ํด๋ž˜์Šค, ์œ„์™€ ๋™์ผํ•˜๋ฏ€๋กœ ์ƒ๋žต

ํ•˜๋‚˜์˜ ๊ฐ์ฒด ํƒ€์ž…์— 2๊ฐ€์ง€ ์ด์ƒ์˜ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌ

1. Comparer ํด๋ž˜์Šค extends
2. Compare ๋ฉ”์„œ๋“œ๋ฅผ override ํ•˜๋Š” ์ƒˆ๋กœ์šด ์ด๋ฆ„ ์—†๋Š” ํด๋ž˜์Šค๋ฅผ ์ •์˜
3. ํ•ด๋‹น ํด๋ž˜์Šค์˜ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

- ๊ทธ๋ ‡๋‹ค๋ฉด Comparer ๊ฐ์ฒด๋“ค์€ ์–ด๋””์— ๋‘˜ ๊ฒƒ์ธ๊ฐ€?
    : ๋ฐ์ดํ„ฐ ๊ฐ์ฒด์˜ member๋กœ ๋‘”๋‹ค.
    : ์ •๋ ฌ ์‹œ Array.sort(fruits, new xxxComparer()); ๋กœ ์‚ฌ์šฉํ•œ๋‹ค.
  • Comparer์˜ ์‚ฌ์šฉ
    public class Fruit
    {
        public String name;
        
        public int quantity;
        
        public Fruit(String name, int quantity)
        {
            
            this.name = name;
            
            this.quantity = quantity;
            
        }
        
        // Comparer์˜ ์ต๋ช… ํด๋ž˜์Šค ์ •์˜ ํ›„ Compare ๋ฉ”์„œ๋“œ ์žฌ์ •์˜(์ด๋ฆ„์ˆœ)
        public class nameComparer : Comparer<Fruit>
        {
            public override int Compare(Fruit o1, Fruit o2)
            {
                return String.Compare(o1.name, o2.name);
            }
        }
        
        // Comparer์˜ ์ต๋ช… ํด๋ž˜์Šค ์ •์˜ ํ›„ Compare ๋ฉ”์„œ๋“œ ์žฌ์ •์˜(์žฌ๊ณ  ์ˆ˜๋Ÿ‰๋ณ„)
        public class quantityComparer : Comparer<Fruit>
        {
            public override int Compare(Fruit o1, Fruit o2)
            {
                return o1.quantity - o2.quantity;
            }
        }
        
    }
    
    //====================================================//
    
    // ์‹คํ–‰ ํ…Œ์ŠคํŠธ ํด๋ž˜์Šค
    public class test()
    {
        public static void Main(string[] args)
        {
            Fruit[] fruits = new Fruit[4];
    
            fruits[0] = new Fruit("Pineapple", 70);
            fruits[1] = new Fruit("Apple", 100);
            fruits[2] = new Fruit("Orange", 80);
            fruits[3] = new Fruit("Banana", 90);
    
            Array.Sort(fruits, new nameComparer());
            // OR
            Array.Sort(fruits, new quantityComparer());
    
            foreach (Fruit member in fruits)
            {
                Console.WriteLine(member);
            }
        }
    }


๊ฑฐํ’ˆ ์ •๋ ฌ


  • ๊ฐ ๋ฃจํ”„ ์‹œ ํ–‰๋™

    • ์ธ์ ‘ํ•œ ์›์†Œ๋ฅผ ๋น„๊ตํ•˜์—ฌ ํฐ ๊ฐ’์„ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ์ด๋™์‹œํ‚จ๋‹ค.
    • ๋‹ค์Œ ํšŒ์ฐจ ๋ฃจํ”„๋•Œ ๋งจ ์™ผ์ชฝ ์›์†Œ๋ฅผ ์ œ์™ธํ•œ๋‹ค.
  • ๋ฃจํ”„์˜ ์‹œ์ž‘์ด ๋งจ ์˜ค๋ฅธ์ชฝ์ด ๋  ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณตํ•œ๋‹ค.



// ๋ฐฉ๋ฒ• 1
public static void bubbleSort(int[] n)
{
    // ์ž„์‹œ๋กœ ์ €์žฅํ•  ๋ณ€์ˆ˜ ์„ ์–ธ
    int temp = 0;
    // ์ •๋ ฌ์ด ํ•„์š”ํ•œ ๋ฐฐ์—ด์˜ ๊ธธ์ด๋งŒํผ ๋ฃจํ”„
    for (int i = 0; i < n.length; i++)
    {
        // ์ˆœํšŒํ•˜๋ฉด์„œ ๋น„๊ตํ•  ์‹ค์ œ ๋ฃจํ”„
        for (int j = i + 1; j < n.length; j++)
        {
            // ์ „ ์š”์†Œ์˜ ๊ฐ’์ด ํฌ๋ฉด
            if (n[i] > n[j])
            {
                // ์ž„์‹œ ๋ณ€์ˆ˜์— ์ž‘์€ ์›์†Œ์˜ ๊ฐ’์„ ์ €์žฅํ•˜๊ณ 
                temp = n[j];
                // ์ž‘์€ ์›์†Œ์˜ ์œ„์น˜์— ํฐ ์›์†Œ์˜ ๊ฐ’์„ ์ €์žฅํ•˜๊ณ 
                n[j] = n[i];
                // ํฐ ์›์†Œ์˜ ์œ„์น˜์— ์ž„์‹œ ๋ณ€์ˆ˜์˜ ๊ฐ’์„ ์ €์žฅ
                n[i] = temp;
            }
        }
    }
}

// ๋ฐฉ๋ฒ• 2
public static void bubbleSort2(int[] n)
{
    // flag ๋ณ€์ˆ˜
    boolean switched;
    do
    {
        // ๋ฐ˜๋ณต๋ฌธ์„ ๋๋‚ผ ์ˆ˜ ์žˆ๊ฒŒ false๋กœ ๋ณ€ํ™˜
        switched = false;
        // ์ •๋ ฌ์ด ํ•„์š”ํ•œ ๋ฐฐ์—ด์˜ ๊ธธ์ด๋งŒํผ ๋ฃจํ”„
        for (int i = 0; i < n.length - 1; i++)
        {
            if (n[i + 1] < n[i])
            {
                // ์ž„์‹œ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๋ฉด์„œ ์ž‘์€ ์›์†Œ ๊ฐ’์„ ์ €์žฅํ•˜๊ณ 
                int tmp = n[i + 1];
                // ์ž‘์€ ์›์†Œ์˜ ์œ„์น˜์— ํฐ ์›์†Œ์˜ ๊ฐ’์„ ์ €์žฅํ•˜๊ณ 
                n[i + 1] = n[i];
                // ํฐ ์›์†Œ์˜ ์œ„์น˜์— ์ž„์‹œ ๋ณ€์ˆ˜์˜ ๊ฐ’์„ ์ €์žฅ
                n[i] = tmp;
                // ๊ตํ™˜์ด ๋˜์—ˆ์œผ๋ฏ€๋กœ flag๋ฅผ true๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฃจํ”„ ๋ฐ˜๋ณต
                switched = true;
            }
        }
    // ๊ตํ™˜์ด ์—†์„ ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณต
    } while (switched);
}

์‚ฝ์ž… ์ •๋ ฌ


  • ๊ฐ ๋ฃจํ”„ ์‹œ ํ–‰๋™

    • ์‹œ์ž‘ํšŒ์ฐจ + 1์˜ ์œ„์น˜ ์›์†Œ๋ฅผ ์ •๋ ฌ๋œ ๋ฐฐ์—ด๊ณผ ๋น„๊ตํ•œ๋‹ค.
    • ์ž์‹ ์˜ ์œ„์น˜๋ฅผ ์ฐพ์•„ ์‚ฝ์ž…ํ•œ๋‹ค.
  • ๋ฃจํ”„์˜ ์‹œ์ž‘์ด ๋งจ ์˜ค๋ฅธ์ชฝ์ด ๋  ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณตํ•œ๋‹ค.



public static void insertionSort(int[] n)
{
    // ์ •๋ ฌ์ด ํ•„์š”ํ•œ ๋ฐฐ์—ด์˜ ๊ธธ์ด๋งŒํผ ๋ฃจํ”„, 2๋ฒˆ์งธ ์›์†Œ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋ฏ€๋กœ i ๋Š” 1๋กœ ์ดˆ๊ธฐํ™”
    for (int i = 1; i < n.length; i++)
    {
        // ๋ฃจํ”„ํ•˜๋ฉฐ ๋น„๊ตํ•  ์›์†Œ
        int key = n[i];
        // ๋น„๊ต ๋Œ€์ƒ์ด ๋˜๋Š” i ๋ณด๋‹ค ์•ž์— ์žˆ๋Š” ์›์†Œ์˜ ์œ„์น˜
        int j = i - 1;
        // j ๊ฐ€ 0๋ณด๋‹ค ์ž‘์•„์งˆ ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณต
        while (j >= 0)
        {
            // ๋น„๊ตํ•  ์›์†Œ ๊ฐ’๋ณด๋‹ค ๋น„๊ต ๋Œ€์ƒ์˜ ๊ฐ’์ด ํฌ๋ฉด
            if(n[j] > key)
            {
                // ๋น„๊ต ๋Œ€์ƒ์˜ ๊ฐ’์„ key์™€ n[j] ์‚ฌ์ด์— ์‚ฝ์ž…
                n[j + 1] = n[j];
                // j ๊ฐ์†Œ
                j--;
            }
        }
        // ๋ฃจํ”„๊ฐ€ ๋๋‚˜๋ฉด key ๊ฐ’์„ ์‚ฝ์ž…
        n[j + 1] = key;
    }
}

์„ ํƒ ์ •๋ ฌ


  • ๊ฐ ๋ฃจํ”„ ์‹œ ํ–‰๋™

    • ๋ฃจํ”„์˜ ์ตœ๋Œ€ ์›์†Œ๋ฅผ ์ฐพ๋Š”๋‹ค.
    • ์ตœ๋Œ€ ์›์†Œ์™€ ๋งจ ์˜ค๋ฅธ์ชฝ ์›์†Œ๋ฅผ ๊ตํ™˜ํ•œ๋‹ค.
    • ๋งจ ์˜ค๋ฅธ์ชฝ ์›์†Œ๋ฅผ ์ œ์™ธํ•œ๋‹ค.
  • ํ•˜๋‚˜์˜ ์›์†Œ๋งŒ ๋‚จ์„ ๋•Œ๊นŒ์ง€ ์œ„์˜ ๋ฃจํ”„๋ฅผ ๋ฐ˜๋ณตํ•œ๋‹ค.



public static void selectionSort(int[] n)
{
    // ์ž„์‹œ๋กœ ์ €์žฅํ•  ๋ณ€์ˆ˜ ์„ ์–ธ
    int temp = 0;

    // ์ •๋ ฌ์ด ํ•„์š”ํ•œ ๋ฐฐ์—ด์˜ ๊ธธ์ด๋งŒํผ ๋ฃจํ”„
    for (int i = 0; i < n.length; i++)
    {
        // ์ตœ์†Ÿ๊ฐ’์˜ ์œ„์น˜๋ฅผ ์ €์žฅํ•  ๋ณ€์ˆ˜
        int min = i;
        // ๋ฐฐ์—ด์˜ ๋์—์„œ๋ถ€ํ„ฐ i ์œ„์น˜๊นŒ์ง€ ๋น„๊ตํ•  ๋ฃจํ”„
        for (int j = n.length - 1; j > i; j--)
        {
            // ๋น„๊ตํ•˜๋Š” ๊ฐ’์ด ์ตœ์†Ÿ๊ฐ’๋ณด๋‹ค ์ž‘์œผ๋ฉด
            if (n[j] < n[min])
                // ์„œ๋กœ์˜ ์œ„์น˜ ๊ฐ’์„ ๋ณ€๊ฒฝ
                min = j;
        }
        // ์ž„์‹œ ๋ณ€์ˆ˜์— ํ˜„์žฌ ๊ฐ’ ์ €์žฅ
        temp = n[i];
        // i์˜ ์›์†Œ ๊ฐ’์€ ์ตœ์†Ÿ๊ฐ’์ด ๋˜์–ด์•ผ ํ•˜๋ฏ€๋กœ ๊ตํ™˜
        n[i] = n[min];
        // ์ตœ์†Ÿ๊ฐ’์ด์—ˆ๋˜ ์›์†Œ์— ์ž„์‹œ ๋ณ€์ˆ˜์˜ ๊ฐ’์„ ์ €์žฅ
        n[min] = temp;
    }
}

ํ€ต ์ •๋ ฌ


  • ์ž„์˜์˜ pivot ๊ฐ’์„ ์ง€์ •ํ•œ๋‹ค.

  • ๊ฐ ๋ฃจํ”„ ์‹œ ํ–‰๋™

    • pivot ๋ณด๋‹ค ํฐ ๊ฐ’์„ pivot index ๋ณด๋‹ค ์™ผ์ชฝ์—์„œ ์ฐพ์•„ ํฐ ๊ฐ’์ด ๋‚˜ํƒ€๋‚  ๋•Œ๊นŒ์ง€ i(index)๋ฅผ ์ฆ๊ฐ€์‹œํ‚จ๋‹ค.
    • pivot ๋ณด๋‹ค ์ž‘์€ ๊ฐ’์„ pivot index ๋ณด๋‹ค ์˜ค๋ฅธ์ชฝ์—์„œ ์ฐพ์•„ ์ž‘์€ ๊ฐ’์ด ๋‚˜ํƒ€๋‚  ๋•Œ๊นŒ์ง€ j(index)๋ฅผ ๊ฐ์†Œ์‹œํ‚จ๋‹ค.
    • pivot ์„ ๊ธฐ์ค€์œผ๋กœ ๊ฐ’ ๋น„๊ต๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ๋‹ค๋ฉด index ๊ฒฐ๊ณผ i , j ๋ฅผ ๋น„๊ตํ•œ๋‹ค.
    • i ๊ฐ’์ด j ๊ฐ’๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค๋ฉด pivot ์„ ๊ธฐ์ค€์œผ๋กœ ๊ตํ™˜์„ ํ•ด์•ผ ํ•  ๊ฐ’์ด ์กด์žฌํ•œ๋‹ค๋Š” ๋œป์ด๋‹ค.
    • ๊ฐ’์„ ๊ตํ™˜ํ•œ ๋’ค i ๋Š” ์ฆ๊ฐ€, j ๋Š” ๊ฐ์†Œ์‹œํ‚จ๋‹ค.
  • i ๊ฐ€ j ๋ณด๋‹ค ํด ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณตํ•œ๋‹ค.



// ํ€ต ์ •๋ ฌ : ๋ฆฌ์ŠคํŠธ ํ˜•ํƒœ
public static List<Integer> quickSort(List<Integer> n)
{
    // ์žฌ๊ท€๋ฅผ ๋๋‚ผ ์กฐ๊ฑด, ๋ฆฌ์ŠคํŠธ์˜ ํฌ๊ธฐ๊ฐ€ 1์ดํ•˜๋ผ๋ฉด ์ •๋ ฌํ•  ํ•„์š”๊ฐ€ ์—†์Œ
    if (n.size() < 2)
        return n;
    
    // ์ž„์˜์˜ ๊ธฐ์ค€ ์ •์˜
    int pivot = n.get(0);
    
    // ํ”ผ๋ด‡์„ ๊ธฐ์ค€์œผ๋กœ ์™ผ์ชฝ์— ์œ„์น˜ํ•  ๋ฆฌ์ŠคํŠธ
    List<Integer> lower = new ArrayList<Integer>();
    // ํ”ผ๋ด‡์„ ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฅธ์ชฝ์— ์œ„์น˜ํ•  ๋ฆฌ์ŠคํŠธ
    List<Integer> higher = new ArrayList<Integer>();
    
    // ์ •๋ ฌ์ด ํ•„์š”ํ•œ ๋ฆฌ์ŠคํŠธ์˜ ํฌ๊ธฐ๋งŒํผ ๋ฃจํ”„, ํ”ผ๋ด‡์„ 0์œผ๋กœ ์žก์•˜์œผ๋‹ˆ i ๋Š” 1๋ถ€ํ„ฐ ์‹œ์ž‘
    for (int i = 1; i < n.size(); i++)
    {
        // ํ”ผ๋ด‡๋ณด๋‹ค ํ˜„์žฌ์˜ ๊ฐ’์ด ์ž‘์œผ๋ฉด
        if (pivot > n.get(i))
            // ์™ผ์ชฝ์— ์ถ”๊ฐ€
            lower.add(n.get(i));
        else
            // ์•„๋‹ˆ๋ผ๋ฉด ์˜ค๋ฅธ์ชฝ์— ์ถ”๊ฐ€
            higher.add(n.get(i));
    }
    
    // ์™ผ์ชฝ์— ์œ„์น˜ํ•˜๋Š” ๋ฆฌ์ŠคํŠธ๋ฅผ ์žฌ๊ท€ํ•˜์—ฌ ์ •๋ ฌ๋œ ํ˜•ํƒœ๋กœ ๊ตฌํ˜„
    List<Integer> answer = quickSort(lower);
    // ํ”ผ๋ด‡์˜ ๊ฐ’์€ ์ค‘๊ฐ„์— ์œ„์น˜ํ•ด์•ผํ•จ
    answer.add(pivot);
    // ๋‚˜๋จธ์ง€์˜ ๊ฐ’์€ ์˜ค๋ฅธ์ชฝ์— ์œ„์น˜ํ•˜๋ฏ€๋กœ ์ „์ฒด ๋ฆฌ์ŠคํŠธ๋ฅผ ํ•ฉ์นจ
    answer.addAll(quickSort(higher));
    
    // ํ•ฉ์นœ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ฐ˜ํ™˜
    return answer;
}

// ํ€ต ์ •๋ ฌ : ๋ฐฐ์—ด ํ˜•ํƒœ
public static void quickSort(int n[], int lower, int higher)
{
    // lower์˜ ๊ฐ’์ด higher์˜ ํฌ๊ธฐ๋ณด๋‹ค ํฌ๋‹ค๋ฉด
    if (lower < higher)
    {
        // ํ”ผ๋ด‡์€ ๋ฐฐ์—ด์„ ๋ถ„ํ• ํ•˜์—ฌ ๋ฐ˜ํ™˜๋œ ๊ฐ’์œผ๋กœ ์„ ์–ธ
        int pivot = partition(n, lower, higher);
        
        // ์™ผ์ชฝ์— ์œ„์น˜ํ•˜๋Š” ๋ฐฐ์—ด์„ ์žฌ๊ท€ํ•˜์—ฌ ์ •๋ ฌ
        quickSort(n, lower, pivot - 1);
        // ์˜ค๋ฅธ์ชฝ์— ์œ„์น˜ํ•˜๋Š” ๋ฐฐ์—ด์„ ์žฌ๊ท€ํ•˜์—ฌ ์ •๋ ฌ
        quickSort(n, pivot + 1, higher);
    }
    
}

// ํ€ต ์ •๋ ฌ : ์žฌ๊ท€ํ˜ธ์ถœ(๋ถ„ํ• )
public static int partition(int[] n, int lower, int higher)
{
    // ํ”ผ๋ด‡์˜ ๊ฐ’์€ ๋ฐฐ์—ด์˜ ์ค‘์•™
    int pivot = n[(lower + higher) / 2];
    // ์™ผ์ชฝ ๊ธฐ์ค€ ๊ฐ’์ด ์˜ค๋ฅธ์ชฝ ๊ธฐ์ค€ ๊ฐ’๋ณด๋‹ค ์ž‘์„ ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณต
    while (lower < higher)
    {
        // ํ”ผ๋ด‡๋ณด๋‹ค ์™ผ์ชฝ์˜ ์›์†Œ๊ฐ€ ์ž‘๋‹ค๋ฉด lower๋ฅผ ์ฆ๊ฐ€
        while ((n[lower] < pivot) && (lower < higher))
            lower++;
        // ํ”ผ๋ด‡๋ณด๋‹ค ์˜ค๋ฅธ์ชฝ์˜ ์›์†Œ๊ฐ€ ํฌ๋‹ค๋ฉด higher๋ฅผ ๊ฐ์†Œ
        while ((n[higher] > pivot) && (lower < higher))
            higher--;
        
        if (lower < higher)
        {
            // ๊ตํ™˜
            int temp = n[lower];
            n[lower] = n[higher];
            n[higher] = temp;
        }
    }

    // while๋ฌธ์ด ๋๋‚˜๋Š” ์‹œ์ ์€ lower๊ฐ€ higher์™€ ๊ฐ™์•„์งˆ ๋•Œ
    return lower;
}

๋ถ„ํ• -์ •๋ณต(Divide and Conquer) ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด๋ž€?

  • ํ•ด๊ฒฐํ•˜๊ธฐ ํž˜๋“  ์ฃผ ๋ฌธ์ œ๋ฅผ ๋ถ€ ๋ฌธ์ œ๋กœ ๋ถ„ํ• ํ•˜์—ฌ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐฉ๋ฒ•

  • ๋ณดํ†ต ์žฌ๊ท€ ํ•จ์ˆ˜(Recursive Function)๋กœ ๊ตฌํ˜„

    • ๋ถ€ ๋ฌธ์ œ๋กœ ๋ถ„ํ• ํ•˜์—ฌ ์ ์šฉํ•  ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ์ž„์˜๋กœ ์„ ํƒ ๊ฐ€๋Šฅ
    • ์žฌ๊ท€ ํ˜ธ์ถœ์„ ์‚ฌ์šฉํ•œ ํ•จ์ˆ˜๋Š” ํ•จ์ˆ˜ ํ˜ธ์ถœ ์˜ค๋ฒ„ํ—ค๋“œ ๋•Œ๋ฌธ์— ์‹คํ–‰ ์†๋„ ๊ฐ์†Œ
    • ๋น ๋ฅธ ์‹คํ–‰์ด๋‚˜ ๋ถ€ ๋ฌธ์ œ ํ•ด๊ฒฐ ์ˆœ์„œ ์„ ํƒ์„ ์œ„ํ•ด ์žฌ๊ท€ ํ˜ธ์ถœ์ด ์•„๋‹Œ ์Šคํƒ(Stack), ํ(Queue) ๋“ฑ์˜ ์ž๋ฃŒ๊ตฌ์กฐ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ถ„ํ•  ์ •๋ณต๋ฒ•์„ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ๋„ ๊ฐ€๋Šฅ
  • ์˜์‚ฌ์ฝ”๋“œ ํ‘œํ˜„

    function F(x):
    if F(x)์˜ ๋ฌธ์ œ๊ฐ€ ๊ฐ„๋‹จ then:
        return F(x)์„ ์ง์ ‘ ๊ณ„์‚ฐํ•œ ๊ฐ’
    else:
        x ๋ฅผ y1, y2๋กœ ๋ถ„ํ• 
        F(y1)๊ณผ F(y2)๋ฅผ ํ˜ธ์ถœ
        return F(y1), F(y2)๋กœ๋ถ€ํ„ฐ F(x)๋ฅผ ๊ตฌํ•œ ๊ฐ’


ํ•ฉ๋ณ‘ ์ •๋ ฌ


  • ๋ฆฌ์ŠคํŠธ์˜ ๊ธธ์ด๊ฐ€ 1 ์ดํ•˜์ด๋ฉด ์ด๋ฏธ ์ •๋ ฌ๋œ ๊ฒƒ์œผ๋กœ ๋ณธ๋‹ค. ๊ทธ๋ ‡์ง€ ์•Š์€ ๊ฒฝ์šฐ์—๋Š”
  • ๋ถ„ํ• (divide) : ์ •๋ ฌ๋˜์ง€ ์•Š์€ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ ˆ๋ฐ˜์œผ๋กœ ์ž˜๋ผ ๋น„์Šทํ•œ ํฌ๊ธฐ์˜ ๋‘ ๋ถ€๋ถ„ ๋ฆฌ์ŠคํŠธ๋กœ ๋‚˜๋ˆˆ๋‹ค.
  • ์ •๋ณต(conquer) : ๊ฐ ๋ถ€๋ถ„ ๋ฆฌ์ŠคํŠธ๋ฅผ ์žฌ๊ท€์ ์œผ๋กœ ํ•ฉ๋ณ‘ ์ •๋ ฌ์„ ์ด์šฉํ•ด ์ •๋ ฌํ•œ๋‹ค.
  • ๊ฒฐํ•ฉ(combine) : ๋‘ ๋ถ€๋ถ„ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋‹ค์‹œ ํ•˜๋‚˜์˜ ์ •๋ ฌ๋œ ๋ฆฌ์ŠคํŠธ๋กœ ํ•ฉ๋ณ‘ํ•œ๋‹ค. ์ด๋•Œ ์ •๋ ฌ ๊ฒฐ๊ณผ๊ฐ€ ์ž„์‹œ๋ฐฐ์—ด์— ์ €์žฅ๋œ๋‹ค.
  • ๋ณต์‚ฌ(copy) : ์ž„์‹œ ๋ฐฐ์—ด์— ์ €์žฅ๋œ ๊ฒฐ๊ณผ๋ฅผ ์›๋ž˜ ๋ฐฐ์—ด์— ๋ณต์‚ฌํ•œ๋‹ค.


// ๋ณ‘ํ•ฉ ์ •๋ ฌ ํ˜ธ์ถœ
public static void mergeSort(int[] arr)
{
    // ์ •๋ ฌ์— ์‚ฌ์šฉํ•  ๋™์ผํ•œ ๊ธธ์ด์˜ ๋ฐฐ์—ด ์„ ์–ธ
    int[] temp = new int[arr.length];
    // ์žฌ๊ท€ํ•จ์ˆ˜ ํ˜ธ์ถœ
    mergeSort(arr, temp, 0, arr.length - 1);
}

// ๋ณ‘ํ•ฉ ์ •๋ ฌ ์‹œ์ž‘
public static void mergeSort(int[] arr, int[] temp, int start, int end)
{
    // ์‹œ์ž‘ ์œ„์น˜ ๊ฐ’์ด ์ข…๋ฃŒ ์œ„์น˜ ๊ฐ’๋ณด๋‹ค ์ž‘์„ ๋•Œ๊นŒ์ง€
    if (start < end)
    {
        // ์ค‘์•™๊ฐ’ ๋ณ€์ˆ˜ ์„ ์–ธ
        int mid = (start + end) / 2;
        // ์ฒ˜์Œ๋ถ€ํ„ฐ ์ค‘์•™๊ฐ’๊นŒ์ง€์˜ ์›์†Œ๋ฅผ ์žฌ๊ท€ํ•˜์—ฌ ์ •๋ ฌ
        mergeSort(arr, temp, start, mid);
        // ์ค‘์•™๊ฐ’ ์ดํ›„๋ถ€ํ„ฐ ๋๊นŒ์ง€์˜ ์›์†Œ๋ฅผ ์žฌ๊ท€ํ•˜์—ฌ ์ •๋ ฌ
        mergeSort(arr, temp, mid + 1, end);
        // ์ •๋ ฌ๋œ ๋ฐฐ์—ด์„ ๋ณ‘ํ•ฉ
        merge(arr, temp, start, mid, end);
    }
}

// ์ •๋ ฌ๋œ ๋ฐฐ์—ด ๋ณ‘ํ•ฉ ์‹คํ–‰
public static void merge(int[] arr, int[] temp, int start, int mid, int end)
{
    // ๋ฐฐ์—ด์„ ๊ทธ๋Œ€๋กœ ๋ณต์‚ฌ
    // java ์˜ ๊ฒฝ์šฐ Arrays.copyOf ์“ฐ๋ฉด ๋จ
    for (int i = start; i <= end; i++)
    {
        temp[i] = arr[i];
    }

    // ์™ผ์ชฝ์˜ ์‹œ์ž‘ ์œ„์น˜ ๊ฐ’ ์ €์žฅ
    int part1 = start;
    // ์˜ค๋ฅธ์ชฝ์˜ ์‹œ์ž‘ ์œ„์น˜ ๊ฐ’ ์ €์žฅ
    int part2 = mid + 1;
    // ์ ˆ๋Œ€ ์œ„์น˜ ๊ฐ’ ์ €์žฅ
    int index = start;

    // ์™ผ์ชฝ ์‹œ์ž‘ ์œ„์น˜ ๊ฐ’์ด ์ค‘์•™์— ๋‹ค๋‹ค๋ฅด๊ฑฐ๋‚˜ ์˜ค๋ฅธ์ชฝ ์‹œ์ž‘ ์œ„์น˜ ๊ฐ’์ด ๋์— ๋‹ค๋‹ค๋ฅผ ๋•Œ๊นŒ์ง€
    while (part1 <= mid && part2 <= end)
    {
        // ์™ผ์ชฝ๊ณผ ์˜ค๋ฅธ์ชฝ์˜ ์›์†Œ ๊ฐ’์„ ๋น„๊ต
        if (temp[part1] <= temp[part2])
        {
            // ์™ผ์ชฝ์ด ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์œผ๋ฉด ์‹ค์ œ ๋ฐฐ์—ด์˜ ์ ˆ๋Œ€ ์œ„์น˜์— ๊ฐ’์„ ์ €์žฅํ•˜๊ณ 
            arr[index] = temp[part1];
            // ์™ผ์ชฝ ์‹œ์ž‘ ์œ„์น˜ ๊ฐ’์„ ์ฆ๊ฐ€
            part1++;
        }
        // ์•„๋‹ˆ๋ผ๋ฉด
        else
        {
            // ์‹ค์ œ ๋ฐฐ์—ด์˜ ์ ˆ๋Œ€ ์œ„์น˜์— ์˜ค๋ฅธ์ชฝ ์‹œ์ž‘ ๊ฐ’์„ ์ €์žฅํ•˜๊ณ 
            arr[index] = temp[part2];
            // ์˜ค๋ฅธ์ชฝ ์‹œ์ž‘ ์œ„์น˜ ๊ฐ’์„ ์ฆ๊ฐ€
            part2++;
        }
        // ๋ฃจํ”„๊ฐ€ ๋Œ ๋•Œ๋งˆ๋‹ค ์ ˆ๋Œ€ ์œ„์น˜๊ฐ’์„ ์ฆ๊ฐ€
        index++;
    }

    // part1์€ while ๋ฃจํ”„๊ฐ€ ๋๋‚œ ์‹œ์ ์ด๋ฏ€๋กœ mid์™€ ๊ฐ™๊ฑฐ๋‚˜ ์ž‘์€ ๊ฐ’์ž„
    for (int i = 0; i <= mid - part1; i++)
    {
        // ์‹ค์ œ ๋ฐฐ์—ด์˜ ์ ˆ๋Œ€ ์œ„์น˜์— i ๊ฐ’์„ ๋”ํ•œ ์œ„์น˜๋Š” ์ค‘์•™๊ณผ ๊ฐ™์Œ
        // ๊ฐ’์„ ์˜ฎ๊ฒจ ๋‹ด์•„์„œ ์ €์žฅ
        arr[index + i] = temp[part1 + i];
    }
}

ํž™ ์ •๋ ฌ(๊ฐœ๋…๋งŒ ์ธ์ง€)


  1. n๊ฐœ์˜ ๋…ธ๋“œ์— ๋Œ€ํ•œ ์™„์ „ ์ด์ง„ ํŠธ๋ฆฌ๋ฅผ ๊ตฌ์„ฑํ•œ๋‹ค. ์ด๋•Œ ๋ฃจํŠธ ๋…ธ๋“œ๋ถ€ํ„ฐ ๋ถ€๋ชจ๋…ธ๋“œ, ์™ผ์ชฝ ์ž์‹๋…ธ๋“œ, ์˜ค๋ฅธ์ชฝ ์ž์‹๋…ธ๋“œ ์ˆœ์œผ๋กœ ๊ตฌ์„ฑํ•œ๋‹ค.
  2. ์ตœ๋Œ€ ํž™์„ ๊ตฌ์„ฑํ•œ๋‹ค. ์ตœ๋Œ€ ํž™์ด๋ž€ ๋ถ€๋ชจ๋…ธ๋“œ๊ฐ€ ์ž์‹๋…ธ๋“œ๋ณด๋‹ค ํฐ ํŠธ๋ฆฌ๋ฅผ ๋งํ•˜๋Š”๋ฐ, ๋‹จ๋ง ๋…ธ๋“œ๋ฅผ ์ž์‹๋…ธ๋“œ๋กœ ๊ฐ€์ง„ ๋ถ€๋ชจ๋…ธ๋“œ๋ถ€ํ„ฐ ๊ตฌ์„ฑํ•˜๋ฉฐ ์•„๋ž˜๋ถ€ํ„ฐ ๋ฃจํŠธ๊นŒ์ง€ ์˜ฌ๋ผ์˜ค๋ฉฐ ์ˆœ์ฐจ์ ์œผ๋กœ ๋งŒ๋“ค์–ด ๊ฐˆ ์ˆ˜ ์žˆ๋‹ค.
  3. ๊ฐ€์žฅ ํฐ ์ˆ˜(๋ฃจํŠธ์— ์œ„์น˜)๋ฅผ ๊ฐ€์žฅ ์ž‘์€ ์ˆ˜์™€ ๊ตํ™˜ํ•œ๋‹ค.
  4. 2์™€ 3์„ ๋ฐ˜๋ณตํ•œ๋‹ค.

์‚ฝ์ž…


์‚ญ์ œ



3์ฃผ์ฐจ - ๊ณผ์ œ(์ •๋ ฌ)

  • 1, 2์ฃผ์ฐจ ๋ฌธ์ œ๋ฅผ ์ •๋ ฌ ์•Œ๊ณ ๋ฆฌ์ฆ˜์œผ๋กœ ํ•ด๊ฒฐํ•˜๋ผ.
    • ์ข€ ๋” ํšจ์œจ์ ์ธ ์ˆ˜๋‹จ์„ ์‚ฌ์šฉํ•˜์—ฌ ์‹œ๊ฐ„์„ ๋‹จ์ถ•ํ•˜๋ผ.


๋’ค๋กœ๊ฐ€๊ธฐ