Algorithm

    [1028알고리즘 18]정렬

    정렬 데이터를 순서대로 나열하는 방법을 의미합니다. 버블정렬 앞뒤 숫자 비교해서 정렬: 1st 와 2nd, 2nd와 3nd, 3nd와4th 와 비교 input = [10, 4,2] def bubble_sort(input): n = len(input) for loop1 in range(n - 1): for loop2 in range(n - 1 - loop1): print(loop2, loop2 + 1, input) if input[loop2] > input[loop2 + 1]: input[loop2], input[loop2 + 1] = input[loop2 + 1], input[loop2] return input print(bubble_sort(input)) 선택정렬 선택해서 정렬. : 가장 작은 숫자를 ..

    [1028알고리즘 17]재귀함수(Recursive function)

    팩토리얼 def factorial(n): if n == 1: return 1 ##print(">>", n) return factorial(n - 1) * n print(factorial(5)) 회문(palindrome) 은 순서를 거꾸로 읽어도 제대로 읽은 것과 같은 단어와 문장을 말합니다. 한 글자도 회문 ex) 토마토, 오디오 def is_palindrome(string): string_len = len(string) if string_len

    [1028알고리즘 16]이진탐색 vs 순차탐색

    이진 탐색 알고리즘의 장점 선형 탐색과 비교하여 탐색 시간이 빠르다. (선형 탐색의 경우 시간 복잡도는 T(n) = θ(n)이다. ) 이진 탐색 알고리즘의 단점 정렬된 리스트에서만 사용될 수 있다. 순차탐색의 시간복잡도는 O(n) 이진탐색의 시간복잡도는 O(logN) finding_target = 14 finding_numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] def is_existing_target_number_Sequential(target, array): find_count = 0 for idx in range(len(finding_numbers)): find_count += 1 if finding_numbers[idx] ==..

    [1028알고리즘 15]트리, 힙

    트리 계층형 비선형 자료구조.(큐, 스택 : 선형구조) Node : 트리에서 데이터를 저장하는 기본요소 Root Node : 트리 맨 위에 있는 노드 Level: 최상위 노드를 Level 0으로 하였을때 하위 B 브렌치로 연결된 노드의 깊이 Parent Node: 어떤 노드의 하위 레벨에 연결된노드 Child Node : 어떤 노드의 상위 레벨에 연결된 노드 Leaf Node(Terminal Node) Child Node가 하나도 없는 노드 Sibling : 동일한 Parent Node를 가진노드 *자매 형제 시빌링 Depth: 트리에서 Node가 가질 수 있는 최대 Level 이진트리, 이진 탐색트리, 균형트리(AVL, red-black), 이진힙(최대힙, 최소힙) 이진트리 노드가 최대 두 개의 자식을..

    반응형