알고리즘 & 자료구조2 [알고리즘] 6가지 Sorting Basic Sorting problems 총 6가지를 알아보자. Insertion Sort Merge Sort Bubble Sort Selection Sort Heap Sort Quick Sort 1. Insertion sort 2번째 index 부터 비교를 시작한다. 자신보다 낮은 index 값에 있는 value가 자신의 value 보다 크다면 자리를 바꿔주는 알고리즘이다. 아래 그림과 같이 insertion sort가 진행된다. 이를 python으로 작성하면 다음과 같다. def insertionSort(A,n): # A list, n length of list for i in range(1,n): # from index 1 to n-1 key = A[i] # keep value A[i] in key.. 2022. 4. 4. [자료구조] 순차적 자료구조 순차적 자료구조 (Sequential data structures) 순차적 자료구조에(Sequential data structures) 는 크게 총 3가지 있다. 1. 배열, 리스트 Index로 임의의 원소에 접근한다. 삽입 함수 append, insert 함수가 존재한다. 삭제 함수 pop( ), remove( ) 함수가 존재한다. 2. Stack, Queue, Deque 제한된 접근, 삽입 삭제만 허용한다. Stack은 LIFO (last in first out) Queue는 FIFO (first in first out) Dequeue는 (stack+queue) 3. Linked list(연결 리스트) 자신의 값 + 다음값이 주소도 저장한다. 값들이 연속적이지 않은 memory 공간에 흩어져 있고 현.. 2022. 4. 2. 이전 1 다음