일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Loss Function
- 코드업
- OG tag
- AWS
- 순환참조
- oauth
- YOLOv5
- 커스텀 데이터 학습
- pandas
- 졸프
- matplotlib
- javascript
- 양방향 매핑
- idToken
- google cloud
- JPA
- @Transactional
- Spring Boot
- react native
- Expo
- google 로그인
- 2021 제9회 문화공공데이터 활용경진대회
- marksense.ai
- yolo
- google login
- C++
- skt fellowship 3기
- Spring
- STT
- html
Archives
- Today
- Total
민팽로그
[정렬 알고리즘] Bubble Sort 본문
Bubble Sort
- 인접한 원소를 하나하나 비교하여 가장 큰 수를 찾아 맨 끝으로 보내면서 정렬하는 알고리즘
- n^2의 시간 복잡도를 갖음. for문을 돌며 (n - 1) * (n - 2) * ... * 2 * 1 번 연산하게 됨
- 시간 복잡도를 생각했을 때 속도가 느려 효율성은 떨어지지만 알고리즘이 단순하여 빠르고 간단하게 구현할 수 있음
예제 코드(Java)
public class Test {
public static void main(String[] args) {
int [] a = new int[10];
for(int i = 0; i < a.length; i++) {
System.out.print(a[i] = (int) (Math.random() * 10));
}
//for(int i = a.length - 1; i > 0; i--) {
for(int i = 0; i < a.length - 1; i++) {
//for (int j = 0; j < i; j++) {
for (int j = 0; j < a.length - 1 - i; j++) {
if(a[j] > a[j + 1]) {
int temp = a[j + 1];
a[j + 1] = a[j];
a[j] = temp;
changed = true;
}
}
}
}
}
'자료구조&알고리즘' 카테고리의 다른 글
그리디(Greedy, 탐욕) 알고리즘 (0) | 2021.12.29 |
---|---|
분할 정복(Divide&Conquer) 알고리즘 (0) | 2021.11.13 |
Comments