pullwall
Well done! 코딩
pullwall
전체 방문자
오늘
어제
  • 분류 전체보기 (151)
    • 개발환경 (2)
    • java study (21)
    • 백준 단계별 (51)
    • 알고리즘 (3)
    • AI (43)
    • 클라우드 (3)
      • Kubernetes in Google (3)
    • 논문 (5)
    • 리눅스 (1)
    • AWS (4)
    • 수학 (15)
    • 기타 (1)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 수학
  • LLM
  • 논문리뷰
  • 쿠버네티스
  • 백준
  • 알고리즘
  • dataset
  • pytorch
  • 자바
  • Java
  • 단계별
  • 자바독학
  • Ai
  • Google
  • AWS
  • Kubernetes
  • 정렬
  • 백준 단계별
  • 선택정렬
  • 정렬알고리즘

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
pullwall

Well done! 코딩

[Java] 정렬 알고리즘 - 버블정렬(Bubble Sort)
알고리즘

[Java] 정렬 알고리즘 - 버블정렬(Bubble Sort)

2023. 2. 2. 14:03
728x90
import java.util.Arrays;

public class Bubble_sort {
    public static void main(String[] args){
        int arr[] = {8,3,1,6,7,5,4,2};

        for(int i=1 ; i<arr.length ; i++){
            for(int j=0 ; j<arr.length-1 ; j++){
                if(arr[j]>arr[j+1]){
                    int tmp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = tmp;
                }
            }
        }
        System.out.println(Arrays.toString(arr));
    }
}

https://en.wikipedia.org/wiki/Bubble_sort

 

 

 

버블정렬은 O(n^2)의 시간복잡도를 가지는 정렬 알고리즘이다.

 

아래는 본인이 코드를 이해하며 동작과정을 써놓은 필기이며 참고하길 바란다.

 

 

 

728x90

'알고리즘' 카테고리의 다른 글

[Java] 정렬 알고리즘 - 삽입정렬(Insertion Sort)  (0) 2023.01.27
[Java] 정렬 알고리즘 - 선택정렬(Selection Sort)  (0) 2023.01.27
    '알고리즘' 카테고리의 다른 글
    • [Java] 정렬 알고리즘 - 삽입정렬(Insertion Sort)
    • [Java] 정렬 알고리즘 - 선택정렬(Selection Sort)
    pullwall
    pullwall

    티스토리툴바