김호쭈
DevForYou
김호쭈
전체 방문자
오늘
어제
  • 분류 전체보기 (321)
    • • 데이터베이스(DB) (9)
      • __SQL__ (9)
    • •알고리즘(Algorithm ) (117)
      • 문제풀이 (99)
      • 스터디 (14)
      • 알고리즘 팁 (4)
    • •Compter Science (57)
      • Operating System (25)
      • Computer Network (1)
      • Computer Vision (16)
      • Artificial Intelligence (14)
      • Software Technology (1)
    • • 독서 (36)
      • Design Pattern (24)
      • 객체지향의 사실과 오해 (1)
      • Object Oriented Software En.. (11)
    • • 개발 (26)
      • React (3)
      • node.js (6)
      • Django (11)
      • Spring boot (6)
    • • 개발Tip (4)
      • GitHub (0)
    • •프로젝트 (2)
      • 물물 (2)
    • •App (54)
      • 안드로이드 with Kotlin (50)
      • 코틀린(Kotiln) (4)
    • •회고 (8)
    • •취준일기 (3)
    • • 기타 (2)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • local저장소
  • 깃허브데스크탑
  • KMU_WINK
  • GitHubDesktop
  • 원격저장소
  • Remote저장소
  • 로컬저장소
  • ㄱ

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
김호쭈

DevForYou

•알고리즘(Algorithm )/스터디

[알고리즘] 버블정렬 파이썬

2022. 7. 22. 17:05

# 공부

- reversed 이용 range 뒤집기

 

 

# 코드

import random

def swap(data,index):
  temp = data[index + 1]
  data[index + 1] = data[index]
  data[index] = temp
  print(data, index)

def bubble_sort(input):
  size = len(input)
  data = input
  print(f"size {size}")
  for turn in reversed(range(size)):
    print(f"######### {turn}")
    for index in range(turn):
      if (input[index] > input[index + 1]):
        swap(data,index)
  print(f" sorted {data}")

if __name__ == '__main__':
  input = random.sample(range(100), 10)
  print(f"sample data : {input}")
  bubble_sort(input)

 

# 시간복잡도

O(n^2)

저작자표시 (새창열림)

'•알고리즘(Algorithm ) > 스터디' 카테고리의 다른 글

[알고리즘] 병합정렬(merge-sort) 파이썬  (0) 2022.07.24
[알고리즘] 재귀함수 파이썬, 회문검사  (0) 2022.07.23
[알고리즘] 선택 정렬 파이썬  (0) 2022.07.22
[알고리즘] 삽입정렬 파이썬  (0) 2022.07.22
[정렬] 버블정렬(Bubble Sort) 알고리즘  (0) 2021.05.21
    '•알고리즘(Algorithm )/스터디' 카테고리의 다른 글
    • [알고리즘] 재귀함수 파이썬, 회문검사
    • [알고리즘] 선택 정렬 파이썬
    • [알고리즘] 삽입정렬 파이썬
    • [정렬] 버블정렬(Bubble Sort) 알고리즘
    김호쭈
    김호쭈
    공부하고 정리하고 기록하기

    티스토리툴바