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 all 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)
2 changes: 1 addition & 1 deletion ko/정렬/버블정렬.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@

#### 애니메이션 설명

- [Tute Board](https://boardhub.github.io/tute/?wd=bubbleSortAlgo2)
- [튜트 보드](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)

#### 코드구현

- [자바](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)