4.1 실행 결과
4.2 결과 분석
4.2.1 소요시간
4.2.1.1 Insertion Sort : 102과 103 크기의 배열을 정렬 할 경우0ms 이하의 시간이
걸렸으며 104과 105의 경우에 83ms 8585ms 등으로 n2의 변화량과 비례하여 증가
함을 알 수 있었다
4.2.1.2 Merge Sort : 102과 103 크기의 배열을 정렬 할 경우0ms 이하의 시간이
걸렸으며 104과 105의 경우에도 5ms 48ms 등으로 변화량을 확인 하기 쉽지 않았다
4.2.1.1 Quick Sort : 102, 103, 104 크기의 배열을 정렬 할 경우0ms 이하의 시간이
걸렸으며 105의 경우에도 20ms로 변화량을 확인 하기 쉽지 않았다
4.2.2 cost
4.2.2.1 Insertion Sort : n2값과 비교 해보면 n2의 1/4 정도의 값으로 n2값 증가 비율과
비슷한 양상으로 cost가 증가 했음을 확인 할 수 있다
지수적인 증가량을 확인.
4.2.2.2 Merge Sort : nlogn값과 비교 해보면 nlog의 2/3 정도의 값으로nlogn값 증가
비율과 비슷한 양상으로 cost가 증가 했음을 확인 할 수 있다
4.2.2.3 Quick Sort : nlogn값과 비교 해보면 nlog의 2/3 정도의 값으로 nlogn값 증가
비율과 비슷한 양상으로 cost가 증가 했음을 확인 할 수 있다
4.2.3 알고리듬별 비교
4.2.3.1 소요시간 : O(n2)의 performance를 가지는 IS의 경우 소요시간이 지수적으로
증가하여 다른 알고리듬들에 비교하여 훨씬 많은 변화량을 보였다.
O(nlogn)의 performance를 가지는 MS와 QS의 경우는 IS에에 비하여
월등한 성능을 보여주었으며 둘 사이에서는 QS가 MS에 비하여 나은
성능을 보였다.
4.2.3.1 Cost : IS의 경우 소요 시간과 비슷한 경향을 보였다. MS와QS의 경우 소요시간
측정보다는 변화량을 확실히 확인 할 수 있었다. 변화량의 경우
MS와QS둘은 비슷한 경향을 보였다.
4.2.4 종합
IS의 경우는 n2의 성능으로 인하여 target의 크기 증가에 cost가 지수적으로 증가하는
낮은 성능의 정렬 알고리듬 이었다. MS와QS의 경우 cost는 QS가 더 큰데 소요시간은
MS가 큰 결과를 보였다. 그 이유는 MS에서 target을 나눌때 마다 새로운 배열을 생성하는
오버헤드가 발생하기 때문에 비교의 횟수는 더 적어도 시간이 QS에 비하여 더 소모되는
것으로 보인다.
4.2.1 소요시간
4.2.1.1 Insertion Sort : 102과 103 크기의 배열을 정렬 할 경우0ms 이하의 시간이
걸렸으며 104과 105의 경우에 83ms 8585ms 등으로 n2의 변화량과 비례하여 증가
함을 알 수 있었다
4.2.1.2 Merge Sort : 102과 103 크기의 배열을 정렬 할 경우0ms 이하의 시간이
걸렸으며 104과 105의 경우에도 5ms 48ms 등으로 변화량을 확인 하기 쉽지 않았다
4.2.1.1 Quick Sort : 102, 103, 104 크기의 배열을 정렬 할 경우0ms 이하의 시간이
걸렸으며 105의 경우에도 20ms로 변화량을 확인 하기 쉽지 않았다
4.2.2 cost
4.2.2.1 Insertion Sort : n2값과 비교 해보면 n2의 1/4 정도의 값으로 n2값 증가 비율과
비슷한 양상으로 cost가 증가 했음을 확인 할 수 있다
지수적인 증가량을 확인.
4.2.2.2 Merge Sort : nlogn값과 비교 해보면 nlog의 2/3 정도의 값으로nlogn값 증가
비율과 비슷한 양상으로 cost가 증가 했음을 확인 할 수 있다
4.2.2.3 Quick Sort : nlogn값과 비교 해보면 nlog의 2/3 정도의 값으로 nlogn값 증가
비율과 비슷한 양상으로 cost가 증가 했음을 확인 할 수 있다
4.2.3 알고리듬별 비교
4.2.3.1 소요시간 : O(n2)의 performance를 가지는 IS의 경우 소요시간이 지수적으로
증가하여 다른 알고리듬들에 비교하여 훨씬 많은 변화량을 보였다.
O(nlogn)의 performance를 가지는 MS와 QS의 경우는 IS에에 비하여
월등한 성능을 보여주었으며 둘 사이에서는 QS가 MS에 비하여 나은
성능을 보였다.
4.2.3.1 Cost : IS의 경우 소요 시간과 비슷한 경향을 보였다. MS와QS의 경우 소요시간
측정보다는 변화량을 확실히 확인 할 수 있었다. 변화량의 경우
MS와QS둘은 비슷한 경향을 보였다.
4.2.4 종합
IS의 경우는 n2의 성능으로 인하여 target의 크기 증가에 cost가 지수적으로 증가하는
낮은 성능의 정렬 알고리듬 이었다. MS와QS의 경우 cost는 QS가 더 큰데 소요시간은
MS가 큰 결과를 보였다. 그 이유는 MS에서 target을 나눌때 마다 새로운 배열을 생성하는
오버헤드가 발생하기 때문에 비교의 횟수는 더 적어도 시간이 QS에 비하여 더 소모되는
것으로 보인다.
'ProgRammIng > Algorithm' 카테고리의 다른 글
| Sorting Comparison #4 결과 분석 (0) | 2009/10/02 |
|---|---|
| Sorting Comparison #3 설계 / 구현 cont. (0) | 2009/10/02 |
| Sorting Comparison #3 설계 / 구현 (0) | 2009/10/02 |
| Sorting Comparison #2 알고리듬 분석 (0) | 2009/10/01 |
| Sorting Comparison #1 개요 (0) | 2009/10/01 |
Trackback 0 and
Comment 0
3.3 User Interface
3.3.1 ❶ 실행 결과를 그래프로 보여주는 부분
3.3.2 ❷ 결과를 문자로 보여주는 부분
3.3.3 ❸ 정렬 실행 버튼
3.3.4 ❹ 사용자의 입력을 받아 배열을 만들어 정렬을 하기위한 입력부
3.3.5 ❺ 그래프 y축 단위를 설정하는 콤보박스
3.3.6 ❻ 102부터 105까지의 정렬을 실행하는 기본값으로 초기화
3.3.7 ❼ 화면 정리 버튼
3.3.1 ❶ 실행 결과를 그래프로 보여주는 부분
3.3.2 ❷ 결과를 문자로 보여주는 부분
3.3.3 ❸ 정렬 실행 버튼
3.3.4 ❹ 사용자의 입력을 받아 배열을 만들어 정렬을 하기위한 입력부
3.3.5 ❺ 그래프 y축 단위를 설정하는 콤보박스
3.3.6 ❻ 102부터 105까지의 정렬을 실행하는 기본값으로 초기화
3.3.7 ❼ 화면 정리 버튼
'ProgRammIng > Algorithm' 카테고리의 다른 글
| Sorting Comparison #4 결과 분석 (0) | 2009/10/02 |
|---|---|
| Sorting Comparison #3 설계 / 구현 cont. (0) | 2009/10/02 |
| Sorting Comparison #3 설계 / 구현 (0) | 2009/10/02 |
| Sorting Comparison #2 알고리듬 분석 (0) | 2009/10/01 |
| Sorting Comparison #1 개요 (0) | 2009/10/01 |
Trackback 0 and
Comment 0
3.1 프로그램 구조
3.1.1 sorting package
3.1.1.1 ArrayBuilder : 입력 받은 정수 값 크기의 배열을 uniform 분포의Random 값으로
채워 생성하는 클래스
3.1.1.2 Sort : 각 알고리듬 클래스의 super클래스로서 소요시간과 cost를 구하는
메서드를 포함한다
3.1.1.3 InsertionSort : insertion Sort 구현 클래스
3.1.1.4 mergeSort : merge Sort 구현 클래스
3.1.1.5 quickSort : quick Sort 구현 클래스
3.1.1.6 sortCotrol : UI의 값을 받아 정렬을 구현하는 controller 클래스
- class diagram -
3.1.2 view package
Swing과 JFreeChart를 사용
3.1.2.1 ButtonPanel : 사용자 입력을 받을 button 등을 만드는 클래스
3.1.2.2 ShowGraph : sorting 결과 dataset을 받아 그래프를 출력하는 클래스
3.1.2.3 ShowFrame : 전체 UI frame
3.2 Sorting Class 구현
3.2.1 insertionSort
3.2.2 MergeSort
3.2.3 QuickSort
3.1.1 sorting package
3.1.1.1 ArrayBuilder : 입력 받은 정수 값 크기의 배열을 uniform 분포의Random 값으로
채워 생성하는 클래스
3.1.1.2 Sort : 각 알고리듬 클래스의 super클래스로서 소요시간과 cost를 구하는
메서드를 포함한다
3.1.1.3 InsertionSort : insertion Sort 구현 클래스
3.1.1.4 mergeSort : merge Sort 구현 클래스
3.1.1.5 quickSort : quick Sort 구현 클래스
3.1.1.6 sortCotrol : UI의 값을 받아 정렬을 구현하는 controller 클래스
3.1.2 view package
Swing과 JFreeChart를 사용
3.1.2.1 ButtonPanel : 사용자 입력을 받을 button 등을 만드는 클래스
3.1.2.2 ShowGraph : sorting 결과 dataset을 받아 그래프를 출력하는 클래스
3.1.2.3 ShowFrame : 전체 UI frame
3.2 Sorting Class 구현
3.2.1 insertionSort
package sorting;
public class InsertionSort extends Sort{
public void sort(ArrayBuilder a){
target = a.getArray();
int j=0;
int key=0;
//System.out.print(" Insertion Sorting Begin ... ");
startTime = System.currentTimeMillis();
// the part of the implementation of the Insertion sort algorithm
for(int i = 1 ; i < target.length ; i++){
key=target[i];
j=i-1;
while ((0<=j)&&(target[j]>key)){ comp++;//값을 비교하는 부분
target[j+1]=target[j];
j--;
}
target[j+1]=key;
}
timeCost = System.currentTimeMillis() - startTime;
sortCorrect(target);
a.setArr(target);
}
}
public class InsertionSort extends Sort{
public void sort(ArrayBuilder a){
target = a.getArray();
int j=0;
int key=0;
//System.out.print(" Insertion Sorting Begin ... ");
startTime = System.currentTimeMillis();
// the part of the implementation of the Insertion sort algorithm
for(int i = 1 ; i < target.length ; i++){
key=target[i];
j=i-1;
while ((0<=j)&&(target[j]>key)){ comp++;//값을 비교하는 부분
target[j+1]=target[j];
j--;
}
target[j+1]=key;
}
timeCost = System.currentTimeMillis() - startTime;
sortCorrect(target);
a.setArr(target);
}
}
3.2.2 MergeSort
package sorting;
public class MergeSort extends Sort {
public void sort(ArrayBuilder a){
target = a.getArray();
//System.out.print(" Merge Sorting Begin ... ");
startTime = System.currentTimeMillis();
// the part of the implementation of the Insertion sort algorithm
mergeSort(target,0,target.length-1);
timeCost = System.currentTimeMillis() - startTime;
sortCorrect(target);
a.setArr(target);
}
private void mergeSort(int[] a, int p, int r){
if(p<r){ comp++; //값을 비교하는 부분
int q = (int)((p+r)/2);
mergeSort(a,p,q);
mergeSort(a,q+1,r);
merge(a,p,q,r);
}
}
private void merge(int[] a, int p, int q,int r){
int n1 = q-p+1;
int n2 = r-q;
int left[] = new int[n1+1];
int right[] = new int[n2+1];
for(int i=0;i<n1;i++){
left[i] = a[p+i];
}
for(int i=0;i<n2;i++){
right[i]= a[q+i+1];
}
left[n1]=Integer.MAX_VALUE;
right[n2]=Integer.MAX_VALUE;
int i=0;
int j=0;
for(int k = p ; k <= r ; k++){
if(left[i]<=right[j]){ comp++;//값을 비교하는 부분
a[k]=left[i];
i++;
}else{
a[k]=right[j];
j++;
}
}
}
}
public class MergeSort extends Sort {
public void sort(ArrayBuilder a){
target = a.getArray();
//System.out.print(" Merge Sorting Begin ... ");
startTime = System.currentTimeMillis();
// the part of the implementation of the Insertion sort algorithm
mergeSort(target,0,target.length-1);
timeCost = System.currentTimeMillis() - startTime;
sortCorrect(target);
a.setArr(target);
}
private void mergeSort(int[] a, int p, int r){
if(p<r){ comp++; //값을 비교하는 부분
int q = (int)((p+r)/2);
mergeSort(a,p,q);
mergeSort(a,q+1,r);
merge(a,p,q,r);
}
}
private void merge(int[] a, int p, int q,int r){
int n1 = q-p+1;
int n2 = r-q;
int left[] = new int[n1+1];
int right[] = new int[n2+1];
for(int i=0;i<n1;i++){
left[i] = a[p+i];
}
for(int i=0;i<n2;i++){
right[i]= a[q+i+1];
}
left[n1]=Integer.MAX_VALUE;
right[n2]=Integer.MAX_VALUE;
int i=0;
int j=0;
for(int k = p ; k <= r ; k++){
if(left[i]<=right[j]){ comp++;//값을 비교하는 부분
a[k]=left[i];
i++;
}else{
a[k]=right[j];
j++;
}
}
}
}
3.2.3 QuickSort
package sorting;
public class QuickSort extends Sort {
public void sort(ArrayBuilder a) {
target = a.getArray();
//System.out.print(" Quick Sorting Begin ... ");
startTime = System.currentTimeMillis();
// the part of the implementation of the Insertion sort algorithm
quickSort(target,0,target.length-1);
timeCost = System.currentTimeMillis() - startTime;
sortCorrect(target);
a.setArr(target);
}
private void quickSort(int[] target, int p, int r) {
if(p<r){ comp++;//값을 비교하는 부분
int q = partition(target, p, r);
quickSort(target, p, q-1);
quickSort(target, q+1, r);
}
}
private int partition(int[] target, int p, int r) {
int x = target[r];
int i = p-1;
for(int j = p;j<r;j++){
if(target[j]<=x){ comp++;//값을 비교하는 부분
i++;
exChange(target, i,j);
}
}
exChange(target, i+1,r);
return i+1;
}
private void exChange(int[] target, int i, int j) {
int temp=target[i];
target[i]=target[j];
target[j]=temp;
}
}
public class QuickSort extends Sort {
public void sort(ArrayBuilder a) {
target = a.getArray();
//System.out.print(" Quick Sorting Begin ... ");
startTime = System.currentTimeMillis();
// the part of the implementation of the Insertion sort algorithm
quickSort(target,0,target.length-1);
timeCost = System.currentTimeMillis() - startTime;
sortCorrect(target);
a.setArr(target);
}
private void quickSort(int[] target, int p, int r) {
if(p<r){ comp++;//값을 비교하는 부분
int q = partition(target, p, r);
quickSort(target, p, q-1);
quickSort(target, q+1, r);
}
}
private int partition(int[] target, int p, int r) {
int x = target[r];
int i = p-1;
for(int j = p;j<r;j++){
if(target[j]<=x){ comp++;//값을 비교하는 부분
i++;
exChange(target, i,j);
}
}
exChange(target, i+1,r);
return i+1;
}
private void exChange(int[] target, int i, int j) {
int temp=target[i];
target[i]=target[j];
target[j]=temp;
}
}
'ProgRammIng > Algorithm' 카테고리의 다른 글
| Sorting Comparison #4 결과 분석 (0) | 2009/10/02 |
|---|---|
| Sorting Comparison #3 설계 / 구현 cont. (0) | 2009/10/02 |
| Sorting Comparison #3 설계 / 구현 (0) | 2009/10/02 |
| Sorting Comparison #2 알고리듬 분석 (0) | 2009/10/01 |
| Sorting Comparison #1 개요 (0) | 2009/10/01 |
Trackback 0 and
Comment 0







Prev