Skip to content

Added Korean explanation of Heap Sort + Fix typo #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 12, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions en/Sorting Algorithms/Heap Sort.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,35 @@ or O(n) (equal keys) Best-case performance

`O(1)` Worst case auxiliary


#### Example
```

```
Input data: 4, 10, 3, 5, 1
4(0)
/ \
10(1) 3(2)
/ \
5(3) 1(4)
4(0)
/ \
10(1) 3(2)
/ \
5(3) 1(4)

The numbers in bracket represent the indices in the array
representation of data.

Applying heapify procedure to index 1:
4(0)
/ \
10(1) 3(2)
/ \
4(0)
/ \
10(1) 3(2)
/ \
5(3) 1(4)

Applying heapify procedure to index 0:
10(0)
/ \
5(1) 3(2)
/ \
4(3) 1(4)
10(0)
/ \
5(1) 3(2)
/ \
4(3) 1(4)
The heapify procedure calls itself recursively to build heap
in top down manner.
```
in top down manner.
```

![heap-image](https://upload.wikimedia.org/wikipedia/commons/1/1b/Sorting_heapsort_anim.gif "Heap Sort")

Expand All @@ -68,4 +68,4 @@ The heapify procedure calls itself recursively to build heap

#### Video Explanation

[A video explaining the Selection Sort Algorithm](https://www.youtube.com/watch?v=MtQL_ll5KhQ)
[A video explaining the Heap Sort Algorithm](https://www.youtube.com/watch?v=MtQL_ll5KhQ)
104 changes: 104 additions & 0 deletions ko/정렬/버블정렬.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# 버블 정렬

#### 문제

원소 n개로 이루어진 정렬되지 않은 배열이 주어졌을 때, 배열을 정렬하는 함수를 작성하라

#### 접근방식

- 배열의 첫 번째 원소를 선택한다.
- 다음 원소와 비교한다.
- 다음 원소보다 크다면 교환한다.
- 아니라면 아무것도 하지 않는다.
- 배열의 모든 인덱스에 이 작업을 진행한다.
- 위의 과정을 n번 반복한다.

#### 시간 복잡도

`O(n^2)` 최악의 경우

`O(n)` 최선의 경우

`O(n^2)` 평균 복잡도

#### 공간 복잡도

`O(1)` 최악의 경우

#### 만든 사람

- “Bubble Sort”라는 용어는 1962년 Iverson, K에 의해 처음 사용되었다.

#### 예시

```
배열 = {10, 80, 40, 30}
인덱스들: 0 1 2 3

1. 인덱스 = 0, 숫자 = 10
2. 10 < 80, 아무것도 하지 않고 다음 단계로 넘어간다.

3. 인덱스 = 1, 숫자 = 80
4. 80 > 40, 80과 40을 교환한다.
5. 현재 배열은 {10, 40, 80, 30}

6. 인덱스 = 2, 숫자 = 80
7. 80 > 30, 80과 30을 교환한다.
8. 현재 배열은 {10, 40, 30, 80}

위 단계를 다시 반복한다.

배열 = {10, 40, 30, 80}
인덱스들: 0 1 2 3

1. 인덱스 = 0, 숫자 = 10
2. 10 < 40, 아무것도 하지 않고 다음 단계로 넘어간다.

3. 인덱스 = 1, 숫자 = 40
4. 40 > 30, 40과 30을 교환한다.
5. 현재 배열은 {10, 30, 40, 80}

6. 인덱스 = 2, 숫자 = 40
7. 40 < 80, 아무것도 하지 않는다.
8. 현재 배열은 {10, 30, 40, 80}

위 단계를 다시 반복한다.

배열 = {10, 30, 40, 80}
인덱스들: 0 1 2 3

1. 인덱스 = 0, 숫자 = 10
2. 10 < 30, 아무것도 하지 않고 다음 단계로 넘어간다.

3. 인덱스 = 1, 숫자 = 30
4. 30 < 40, 아무것도 하지 않고 다음 단계로 넘어간다.

5. 인덱스 = 2, 숫자 = 40
6. 40 < 80, 아무것도 하지 않는다.

위 단계에서 교환이 없기 때문에 배열이 정렬되었음을 의미하고, 여기서 멈출 수 있다.
```

#### 코드 구현

- [자바](https://github.com/TheAlgorithms/Java/blob/master/Sorts/BubbleSort.java)
- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/bubble_sort.cpp)
- [파이썬](https://github.com/TheAlgorithms/Python/blob/master/sorts/bubble_sort.py)
- [C#](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/BubbleSorter.cs)
- [고](https://github.com/TheAlgorithms/Go/blob/master/sorts/bubblesort.go)
- [루비](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/bubble_sort.rb)
- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/bubble_sort.c)
- [스칼라](https://github.com/TheAlgorithms/Scala/blob/master/src/main/scala/Sort/BubbleSort.scala)
- [자바스크립트](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/BubbleSort.js)

#### 영상 설명

[버블정렬 알고리즘에 대한 영상 설명](https://www.youtube.com/watch?v=Jdtq5uKz-w4)

#### 그 외

버블 정렬은 싱킹 정렬이라고도 한다.

#### 애니메이션 설명

- [Tute Board](https://boardhub.github.io/tute/?wd=bubbleSortAlgo2)
69 changes: 69 additions & 0 deletions ko/정렬/힙정렬.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# 힙 정렬

#### 문제

정렬되지 않은 n개의 원소로 이루어진 배열이 주어졌을 때, 배열을 정렬하는 함수를 작성하라

#### 접근방식

- 입력 데이터에서 최대 힙을 빌드한다.
- 이때, 가장 큰 원소가 힙의 루트에 저장된다. 해당 원소를 힙의 마지막 원소로 교체한 뒤, 힙의 사이즈를 1 줄인다.
- 힙의 사이즈가 1보다 크다면 위 과정을 반복한다.

#### 시간 복잡도

`O(n log n)` 최악의 경우

`O(n log n)` (고유 키)
or O(n) (동일 키) 최선의 경우

`O(n log n)` 평균 복잡도

#### 공간 복잡도

`O(1)` 최악의 경우

#### 예시

```
입력 원소 : 4, 10, 3, 5, 1
4(0)
/ \
10(1) 3(2)
/ \
5(3) 1(4)

괄호 안의 숫자는 데이터의 배열 인덱스를 나타낸다.

1번 인덱스에 힙 절차 적용 :
4(0)
/ \
10(1) 3(2)
/ \
5(3) 1(4)

0번 인덱스의 힙 절차 적용:
10(0)
/ \
5(1) 3(2)
/ \
4(3) 1(4)
힙 절차는 재귀적으로 호출하여 하향식 방식으로 힙을 빌드한다.
```

![힙 이미지](https://upload.wikimedia.org/wikipedia/commons/1/1b/Sorting_heapsort_anim.gif "Heap Sort")

#### 코드구현

- [자바](https://github.com/TheAlgorithms/Java/blob/master/Sorts/HeapSort.java)
- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/sorting/heap_sort.cpp)
- [파이썬](https://github.com/TheAlgorithms/Python/blob/master/sorts/heap_sort.py)
- [고](https://github.com/TheAlgorithms/Go/blob/master/sorts/heapsort.go)
- [루비](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/heap_sort.rb)
- [C-sharp](https://github.com/TheAlgorithms/C-Sharp/blob/master/Algorithms/Sorters/Comparison/HeapSorter.cs)
- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/heap_sort.c)
- [자바스크립트](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/HeapSort.js)

#### 영상 설명

[힙 정렬 알고리즘에 대한 영상 설명](https://www.youtube.com/watch?v=MtQL_ll5KhQ)