|
2 | 2 |
|
3 | 3 | ## 문제
|
4 | 4 |
|
5 |
| -n개 원소로 구성된 배열이 주어졌을 때, 이 배열을 정렬하는 함수를 구하라. |
| 5 | +원소 n개로 이루어진 정렬되지 않은 배열이 주어졌을 때, 배열을 정렬하는 함수를 작성하라. |
6 | 6 |
|
7 |
| -## 절차 |
| 7 | +## 접근방식 |
8 | 8 |
|
9 |
| -- select the first element of the array |
10 |
| -- compare it with its next element |
11 |
| -- if it is larger than the next element then swap them |
12 |
| -- else do nothing |
13 |
| -- keep doing this for every index of the array |
14 |
| -- repeat the above process n times. |
| 9 | +- 배열의 첫 번째 원소를 선택한다. |
| 10 | +- 다음 원소와 비교한다. |
| 11 | +- 다음 원소보다 크다면 교환한다. |
| 12 | +- 아니라면 아무것도 하지 않는다. |
| 13 | +- 배열의 모든 인덱스에 이 작업을 진행한다. |
| 14 | +- 위의 과정을 n번 반복한다. |
15 | 15 |
|
16 | 16 | ## 시간 복잡도
|
17 | 17 |
|
18 |
| -- 최악: <img src="https://render.githubusercontent.com/render/math?math=O(n^2)"> |
19 |
| -- 최선: <img src="https://render.githubusercontent.com/render/math?math=O(n)"> |
20 |
| -- 평균: <img src="https://render.githubusercontent.com/render/math?math=O(n^2)"> |
| 18 | +$O(n^2)$ 최악의 경우 |
| 19 | + |
| 20 | +$O(n)$ 최선의 경우 |
| 21 | + |
| 22 | +$O(n^2)$ 평균 복잡도 |
21 | 23 |
|
22 | 24 | ## 공간 복잡도
|
23 | 25 |
|
24 |
| -- 최악: <img src="https://render.githubusercontent.com/render/math?math=O(1)"> |
| 26 | +$O(1)$ 최악의 경우 |
25 | 27 |
|
26 | 28 | ## 만든 사람
|
27 | 29 |
|
28 |
| -- [케네스 아이버슨](https://ko.wikipedia.org/wiki/%EC%BC%80%EB%84%A4%EC%8A%A4_%EC%95%84%EC%9D%B4%EB%B2%84%EC%8A%A8): "버블 정렬"이라는 용어를 1962년에 처음으로 사용했다. |
| 30 | +- “Bubble Sort”라는 용어는 1962년 Iverson, K에 의해 처음 사용되었다. |
29 | 31 |
|
30 | 32 | ## 예시
|
31 | 33 |
|
32 | 34 | ```
|
33 |
| -arr[] = {10, 80, 40, 30} |
34 |
| -Indexes: 0 1 2 3 |
| 35 | +배열 = {10, 80, 40, 30} |
| 36 | +인덱스들: 0 1 2 3 |
35 | 37 |
|
36 |
| -1. Index = 0, Number = 10 |
37 |
| -2. 10 < 80, do nothing and continue |
| 38 | +1. 인덱스 = 0, 숫자 = 10 |
| 39 | +2. 10 < 80, 아무것도 하지 않고 다음 단계로 넘어간다. |
38 | 40 |
|
39 |
| -3. Index = 1, Number = 80 |
40 |
| -4. 80 > 40, swap 80 and 40 |
41 |
| -5. The array now is {10, 40, 80, 30} |
| 41 | +3. 인덱스 = 1, 숫자 = 80 |
| 42 | +4. 80 > 40, 80과 40을 교환한다. |
| 43 | +5. 현재 배열은 {10, 40, 80, 30} |
42 | 44 |
|
43 |
| -6. Index = 2, Number = 80 |
44 |
| -7. 80 > 30, swap 80 and 30 |
45 |
| -8. The array now is {10, 40, 30, 80} |
| 45 | +6. 인덱스 = 2, 숫자 = 80 |
| 46 | +7. 80 > 30, 80과 30을 교환한다. |
| 47 | +8. 현재 배열은 {10, 40, 30, 80} |
46 | 48 |
|
47 |
| -Repeat the Above Steps again |
| 49 | +위 단계를 다시 반복한다. |
48 | 50 |
|
49 |
| -arr[] = {10, 40, 30, 80} |
50 |
| -Indexes: 0 1 2 3 |
| 51 | +배열 = {10, 40, 30, 80} |
| 52 | +인덱스들: 0 1 2 3 |
51 | 53 |
|
52 |
| -1. Index = 0, Number = 10 |
53 |
| -2. 10 < 40, do nothing and continue |
| 54 | +1. 인덱스 = 0, 숫자 = 10 |
| 55 | +2. 10 < 40, 아무것도 하지 않고 다음 단계로 넘어간다. |
54 | 56 |
|
55 |
| -3. Index = 1, Number = 40 |
56 |
| -4. 40 > 30, swap 40 and 30 |
57 |
| -5. The array now is {10, 30, 40, 80} |
| 57 | +3. 인덱스 = 1, 숫자 = 40 |
| 58 | +4. 40 > 30, 40과 30을 교환한다. |
| 59 | +5. 현재 배열은 {10, 30, 40, 80} |
58 | 60 |
|
59 |
| -6. Index = 2, Number = 40 |
60 |
| -7. 40 < 80, do nothing |
61 |
| -8. The array now is {10, 30, 40, 80} |
| 61 | +6. 인덱스 = 2, 숫자 = 40 |
| 62 | +7. 40 < 80, 아무것도 하지 않는다. |
| 63 | +8. 현재 배열은 {10, 30, 40, 80} |
62 | 64 |
|
63 |
| -Repeat the Above Steps again |
| 65 | +위 단계를 다시 반복한다. |
64 | 66 |
|
65 |
| -arr[] = {10, 30, 40, 80} |
66 |
| -Indexes: 0 1 2 3 |
| 67 | +배열 = {10, 30, 40, 80} |
| 68 | +인덱스들: 0 1 2 3 |
67 | 69 |
|
68 |
| -1. Index = 0, Number = 10 |
69 |
| -2. 10 < 30, do nothing and continue |
| 70 | +1. 인덱스 = 0, 숫자 = 10 |
| 71 | +2. 10 < 30, 아무것도 하지 않고 다음 단계로 넘어간다. |
70 | 72 |
|
71 |
| -3. Index = 1, Number = 30 |
72 |
| -4. 30 < 40, do nothing and continue |
| 73 | +3. 인덱스 = 1, 숫자 = 30 |
| 74 | +4. 30 < 40, 아무것도 하지 않고 다음 단계로 넘어간다. |
73 | 75 |
|
74 |
| -5. Index = 2, Number = 40 |
75 |
| -6. 40 < 80, do nothing |
| 76 | +5. 인덱스 = 2, 숫자 = 40 |
| 77 | +6. 40 < 80, 아무것도 하지 않는다. |
76 | 78 |
|
77 |
| -Since there are no swaps in above steps, it means the array is sorted and we can stop here. |
| 79 | +위 단계에서 교환이 없기 때문에 배열이 정렬되었음을 의미하고, 여기서 멈출 수 있다. |
78 | 80 | ```
|
79 | 81 |
|
80 | 82 | ## 구현
|
81 | 83 |
|
82 |
| -- [Java](https://github.com/TheAlgorithms/Java/blob/master/Sorts/BubbleSort.java) |
| 84 | +
10000
span>- [자바](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/BubbleSort.java) |
83 | 85 | - [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/bubble_sort.cpp)
|
84 |
| -- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/bubble_sort.py) |
| 86 | +- [파이썬](https://github.com/TheAlgorithms/Python/blob/master/sorts/bubble_sort.py) |
85 | 87 | - [C#](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/BubbleSorter.cs)
|
86 |
| -- [Go](https://github.com/TheAlgorithms/Go/blob/master/sorts/bubblesort.go) |
87 |
| -- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/bubble_sort.rb) |
| 88 | +- [고](https://github.com/TheAlgorithms/Go/blob/master/sorts/bubblesort.go) |
| 89 | +- [루비](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/bubble_sort.rb) |
88 | 90 | - [C](https://github.com/TheAlgorithms/C/blob/master/sorting/bubble_sort.c)
|
89 |
| -- [Scala](https://github.com/TheAlgorithms/Scala/blob/master/src/main/scala/Sort/BubbleSort.scala) |
90 |
| -- [JavaScript](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/BubbleSort.js) |
| 91 | +- [스칼라](https://github.com/TheAlgorithms/Scala/blob/master/src/main/scala/Sort/BubbleSort.scala) |
| 92 | +- [자바스크립트](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/BubbleSort.js) |
91 | 93 |
|
92 | 94 | ## 영상 URL
|
93 | 95 |
|
94 |
| -- [mycodeschool](https://www.youtube.com/watch?v=Jdtq5uKz-w4) |
| 96 | +- [버블정렬 알고리즘에 대한 영상 설명](https://www.youtube.com/watch?v=Jdtq5uKz-w4) |
95 | 97 |
|
96 | 98 | ## 기타
|
97 | 99 |
|
98 |
| -- [Tute Board](https://boardhub.github.io/tute/?wd=bubbleSortAlgo2) |
| 100 | +- 버블 정렬은 싱킹 정렬이라고도 한다. |
| 101 | +- 시각화: [튜트 보드](https://boardhub.github.io/tute/?wd=bubbleSortAlgo2) |
0 commit comments