반응형
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Compiler
- 방송통신대학교
- 교육
- 컴퓨터과학과
- 프로그래밍언어
- Computer
- Algorithms
- Book
- Software
- Programming
- 책
- 영화
- 법
- 컴퓨터
- architecture
- ISBN:89-20-34523-6
- 알고리즘
- 용어
- 컴파일러
- Java
- 운영체제
- Database
- 광고
- 데이터베이스
- OS
- 백과사전
- 인간과 교육
- 영어
- EJB
Archives
- Today
- Total
Digital Intelligence
합병 정렬 ( merge sort ) 본문
반응형
주제(Subject)
--------------------------------------------------------
한글(약어) : 합병 정렬()
영어(약어) : merge sort()
관련개념(Related Concepts)
--------------------------------------------------------
정렬
알고리즘
비교기반 정렬
개요(Summary)
--------------------------------------------------------
분할정복 방법에 따라, 자료를 부분배열로 나눈 후, 오름/내림차순으로 정렬하는 방법.
퀵정렬의 단점을 보완한다.
안정적
제자리정렬 가능함
본문(Body)
--------------------------------------------------------
1. 합병정렬의 성질
2) Wanginator : Merge Sort - JavaApplet
http://www.wanginator.de/studium/applets/mergesort_en.html
3) The Animator :
http://www.cs.hope.edu/alganim/animator/Animator.html
모임,단체(Commutities)
--------------------------------------------------------
1. Hope College Department of Computer Science| 27 Graves Place | Holland, MI 49423
http://www.hope.edu/cs/
블로그,개인 홈페이지 등(Humanities)
--------------------------------------------------------
참고문서(References)
--------------------------------------------------------
* 한국어(Korean)
저자. 역자. "제목". 출판사. 출판년도. (ISBN:)
* 영어(English)
저자. 제목, 판, 출판사. 출판년도. (ISBN:)
1. Wikipedia : Merge Sort
http://en.wikipedia.org/wiki/Merge_sort
2. Wanginator : Merge Sort
http://www.wanginator.de/studium/applets/mergesort_en.html
3. The Complete Collection of Algorithm Animations (CCAA) (Hope College Department of Computer Science| 27 Graves Place | Holland, MI 49423)
http://www.cs.hope.edu/alganim/ccaa/index.html
4. Google Search : type [[merge sort site:*.edu]]@google
http://www.google.com/search?source=ig&hl=en&q=merge+sort+site%3A*.edu
--------------------------------------------------------
한글(약어) : 합병 정렬()
영어(약어) : merge sort()
관련개념(Related Concepts)
--------------------------------------------------------
정렬
알고리즘
비교기반 정렬
개요(Summary)
--------------------------------------------------------
분할정복 방법에 따라, 자료를 부분배열로 나눈 후, 오름/내림차순으로 정렬하는 방법.
퀵정렬의 단점을 보완한다.
안정적
제자리정렬 가능함
본문(Body)
--------------------------------------------------------
1. 합병정렬의 성질
In computer science, merge sort or mergesort is an O(n log n) sorting algorithm. It is easy to implement merge sort such that it is stable, meaning it preserves the input order of equal elements in the sorted output. It is an example of the divide and conquer algorithmic paradigm. It is a comparison sort. The algorithm was invented by John von Neumann in 1945.
- from Wikipedia : Merge Sort
- from Wikipedia : Merge Sort
2. 소스코드
1) Java (from Wanginator)
public class MergeSort {
public static void mergesort (int[] a) {
mergesort(a, 0, a.length-1);
}
private static void mergesort (int[] a, int l, int r) {
//base case: a[l..r] is empty or has only one element
if ( l>=r ) return;
//recursion step: a[l..r] is not empty
//divide into sublists and merge
int m = (l+r)/2;
mergesort (a, l, m);
mergesort (a, m+1, r);
merge (a, l, m, r);
}
//merges to sublists
private static void merge (int[] a, int l, int m, int r) {
//base case: second sublist is empty
if (m+1>r) return;
int[] b = new int[a.length]; //create temporary array
//copy a[l..m] to b[l..m]
for (int i=l; i!=m+1; i++) {
b[i] = a[i];
}
//copy a[m+1..r] to b[m+1..r] in reverse order
for (int i=m+1; i!=r+1; i++) {
b[i] = a[r+m+1-i];
}
//merge b[l..m] with b[m+1..r] to a[l..r]
int k=l; int j=r; //pointer wandering from outside inward
for (int i=l; i!=r+1; i++) {
if (b[k] <= b[j]) a[i] = b[k++];
else a[i] = b[j--];
}
}
}
public static void mergesort (int[] a) {
mergesort(a, 0, a.length-1);
}
private static void mergesort (int[] a, int l, int r) {
//base case: a[l..r] is empty or has only one element
if ( l>=r ) return;
//recursion step: a[l..r] is not empty
//divide into sublists and merge
int m = (l+r)/2;
mergesort (a, l, m);
mergesort (a, m+1, r);
merge (a, l, m, r);
}
//merges to sublists
private static void merge (int[] a, int l, int m, int r) {
//base case: second sublist is empty
if (m+1>r) return;
int[] b = new int[a.length]; //create temporary array
//copy a[l..m] to b[l..m]
for (int i=l; i!=m+1; i++) {
b[i] = a[i];
}
//copy a[m+1..r] to b[m+1..r] in reverse order
for (int i=m+1; i!=r+1; i++) {
b[i] = a[r+m+1-i];
}
//merge b[l..m] with b[m+1..r] to a[l..r]
int k=l; int j=r; //pointer wandering from outside inward
for (int i=l; i!=r+1; i++) {
if (b[k] <= b[j]) a[i] = b[k++];
else a[i] = b[j--];
}
}
}
3. 시뮬레이션
1) Gif Animation
Description Sorting a random list using merge sort Source Self-made using Matlab Date 2006-11-28 ,Author v1: Nuno Nogueira (Nmnogueira), v2: edited by Daniel Miller (cobaltBlue)
2) Wanginator : Merge Sort - JavaApplet
http://www.wanginator.de/studium/applets/mergesort_en.html
3) The Animator :
http://www.cs.hope.edu/alganim/animator/Animator.html
모임,단체(Commutities)
--------------------------------------------------------
1. Hope College Department of Computer Science| 27 Graves Place | Holland, MI 49423
http://www.hope.edu/cs/
블로그,개인 홈페이지 등(Humanities)
--------------------------------------------------------
참고문서(References)
--------------------------------------------------------
* 한국어(Korean)
저자. 역자. "제목". 출판사. 출판년도. (ISBN:)
* 영어(English)
저자. 제목, 판, 출판사. 출판년도. (ISBN:)
1. Wikipedia : Merge Sort
http://en.wikipedia.org/wiki/Merge_sort
2. Wanginator : Merge Sort
http://www.wanginator.de/studium/applets/mergesort_en.html
3. The Complete Collection of Algorithm Animations (CCAA) (Hope College Department of Computer Science| 27 Graves Place | Holland, MI 49423)
http://www.cs.hope.edu/alganim/ccaa/index.html
4. Google Search : type [[merge sort site:*.edu]]@google
http://www.google.com/search?source=ig&hl=en&q=merge+sort+site%3A*.edu
반응형
'B1:기초 Basement' 카테고리의 다른 글
Böhm-Jacopini정리 ( Böhm-Jacopini theorem ) (0) | 2007.05.24 |
---|---|
2-3-4 나무 ( 2-3-4 tree ) (0) | 2007.05.13 |
계수 정렬 ( counting sort ) (0) | 2007.05.13 |
흑적나무 ( red-black tree ) (0) | 2007.05.13 |
ASF, WMA, WMV 동영상 합치기와 기타 변환작업 :: asf tools (0) | 2007.05.10 |