티스토리 뷰
- 범위조건이 있는 경우에 한해서 굉장히 빠른 알고리즘
- 속도는 O(N)
- 단순하게 크기를 기준으로 세는 알고리즘임
public class CountingSort {
int temp;
public static void counting() {
int []count = new int[5];
int array[] = {
1,3,2,4,3,
2,5,3,1,2,
3,4,4,3,5,
1,2,3,5,2,
3,1,4,3,5,
1,2,1,1,1};
for(int i = 0; i < 5; i++) {
count[i] = 0;
}
for(int i = 0; i < 30; i++) {
count[array[i] - 1]++;
}
for(int i = 0; i < 5; i++) {
if(count[i] != 0) {
for(int j = 0; j < count[i]; j++) {
System.out.println((i+1)+" ");
}
}
}
}
public static void main(String[] args) {
counting();
}
'algorithm' 카테고리의 다른 글
[입출력] 10953, 11021, 11718 (0) | 2020.04.07 |
---|---|
[입출력] 1000, 2558, 10950 (0) | 2020.04.06 |
[Algorithm] 다이나믹 프로그래밍(Dynamic programming) (0) | 2020.03.30 |
HeapSort with java (0) | 2020.01.24 |
MergeSort with java (0) | 2020.01.24 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 알고리즘
- 병행프로세스
- 입출력장치
- 인접행렬
- Java
- 클래스
- 스텍
- 운영체제
- 소프트웨어
- 세마포어
- 이진탐색
- 동적프로그래밍
- C++
- 최단경로
- 재귀함수
- javascript
- server side rendering
- C
- stackframe
- Stack
- BFS
- 구조체
- client side rendering
- 자료구조
- dfs
- 퀵정렬
- 배열
- react
- 교착상태
- 인접리스트
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
글 보관함