mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-25 21:23:21 +08:00
Release reviewed gh-pages candidate
This commit is contained in:
@@ -1919,21 +1919,21 @@
|
||||
<li><strong>트리 구조</strong>: 트리, 힙, 해시 테이블이 해당하며, 원소 사이에 일대다 관계가 있다.</li>
|
||||
<li><strong>네트워크 구조</strong>: 그래프가 해당하며, 원소 사이에 다대다 관계가 있다.</li>
|
||||
</ul>
|
||||
<p><ha-svg-figure class="animation-figure" data-book-key="ko/chapter_data_structure/classification_of_data_structure.assets/classification_logic_structure.png" data-dark-src="/assets/figure-svg/figures/5fa2d2a9d83e7b6089b26ac8.json" data-src="/assets/figure-svg/figures/37e120faab31ae5bad25d247.json" style=";--figure-ratio:960.0/540.0"><object data="/ko/chapter_data_structure/classification_of_data_structure.assets/classification_logic_structure.svg" data-theme="light" tabindex="-1" type="image/svg+xml">선형 자료 구조와 비선형 자료 구조</object><object data="/ko/chapter_data_structure/classification_of_data_structure.assets/classification_logic_structure.dark.svg" data-theme="dark" tabindex="-1" type="image/svg+xml">선형 자료 구조와 비선형 자료 구조</object></ha-svg-figure></p>
|
||||
<p align="center"> 그림 3-1 선형 자료 구조와 비선형 자료 구조 </p>
|
||||
<p><ha-svg-figure aria-label="자료 구조의 논리적 관계" class="animation-figure" data-book-key="ko/chapter_data_structure/classification_of_data_structure.assets/classification_logic_structure.png" data-dark-src="/assets/figure-svg/figures/5fa2d2a9d83e7b6089b26ac8.json" data-figure-accessible="" data-src="/assets/figure-svg/figures/37e120faab31ae5bad25d247.json" role="img" style=";--figure-ratio:960.0/540.0"><object aria-hidden="true" data="/ko/chapter_data_structure/classification_of_data_structure.assets/classification_logic_structure.svg" data-theme="light" inert="" tabindex="-1" type="image/svg+xml">선형 자료 구조와 비선형 자료 구조</object><object aria-hidden="true" data="/ko/chapter_data_structure/classification_of_data_structure.assets/classification_logic_structure.dark.svg" data-theme="dark" inert="" tabindex="-1" type="image/svg+xml">선형 자료 구조와 비선형 자료 구조</object></ha-svg-figure></p>
|
||||
<p align="center"> 그림 3-1 선형 자료 구조와 비선형 자료 구조 </p><div class="ha-sr-only figure-description"><h3>그림 3-1 설명: 자료 구조의 논리적 관계</h3><p>순차 배열, 부모-자식 계층, 네트워크 연결, 키-값 매핑의 네 가지 논리적 관계를 비교한다.</p><p>그림의 왼쪽 열은 선형 자료 구조, 오른쪽 열은 비선형 자료 구조이며, 해시 테이블은 두 열 아래에 놓여 키-값 매핑을 따로 보여 준다.</p><table><caption>각 자료 구조의 예시와 연결 관계</caption><thead><tr><th scope="col">자료 구조</th><th scope="col">그림 내 배치</th><th scope="col">그림의 원소와 관계</th></tr></thead><tbody><tr><th scope="row">배열(array)</th><td>선형</td><td>1, 3, 2, 5, 4 순서로 나열</td></tr><tr><th scope="row">연결 리스트(linked list)</th><td>선형</td><td>1→3→2→5→4</td></tr><tr><th scope="row">스택(stack)</th><td>선형</td><td>열린 끝에서 막힌 끝 방향으로 1, 3, 2, 5, 4; 삽입(push)과 꺼내기(pop)가 모두 열린 끝에서 이루어짐</td></tr><tr><th scope="row">큐(queue)</th><td>선형</td><td>꺼내는 끝에서 넣는 끝 방향으로 1, 3, 2, 5, 4; 삽입(push)과 꺼내기(pop)가 서로 다른 끝에서 이루어짐</td></tr><tr><th scope="row">트리(tree)</th><td>비선형</td><td>루트 1의 왼쪽 2·오른쪽 3, 2의 왼쪽 4·오른쪽 5, 3의 왼쪽 6·오른쪽 7; 노드 7개, 세 층</td></tr><tr><th scope="row">그래프(graph)</th><td>비선형</td><td>정점 5개(1~5); 무방향 간선 1—2, 1—3, 2—3, 2—4, 2—5, 3—5, 4—5로 총 7개</td></tr><tr><th scope="row">힙(heap)</th><td>비선형</td><td>루트 1의 왼쪽 3·오른쪽 2, 3의 왼쪽 5·오른쪽 4; 노드 5개, 세 층</td></tr><tr><th scope="row">해시 테이블(hash table)</th><td>두 열 아래 단독 배치</td><td>키 a, b, c가 각각 값 1, 2, 3에 매핑됨</td></tr></tbody></table><p>선형 구조는 원소들 사이에 앞뒤 순서가 있지만 연산이 허용되는 위치의 제약이 서로 다르다. 트리와 힙은 부모-자식 계층을 이루며, 그래프는 한 정점이 여러 이웃을 가질 수 있다. 여기서 비교하는 것은 논리적 관계이며 물리적 저장 방식과 같지 않다. 같은 논리적 관계도 여러 방식으로 구현할 수 있고, 해시 테이블 역시 배열, 연결 리스트, 트리를 조합해 구현할 수 있다.</p></div>
|
||||
<h2 id="312">3.1.2 물리적 구조: 연속과 분산<a class="headerlink" href="#312" title="고유 링크">¶</a></h2>
|
||||
<p><strong>알고리즘 프로그램이 실행될 때 처리 중인 데이터는 주로 메모리에 저장된다</strong>. 아래 그림(3-2)은 컴퓨터 메모리 모듈을 보여 주며, 검은색 칩마다 메모리 공간이 들어 있다. 메모리는 각 셀에 일정한 크기의 데이터를 저장할 수 있는 거대한 Excel 표라고 생각할 수 있다.</p>
|
||||
<p><strong>시스템은 메모리 주소를 통해 원하는 위치의 데이터에 접근한다</strong>. 아래 그림(3-2)과 같이 컴퓨터는 특정 규칙에 따라 표의 각 셀에 번호를 부여하여 모든 메모리 공간이 고유한 메모리 주소를 갖게 한다. 프로그램은 이 주소를 이용해 메모리의 데이터에 접근한다.</p>
|
||||
<p><ha-svg-figure class="animation-figure" data-book-key="ko/chapter_data_structure/classification_of_data_structure.assets/computer_memory_location.png" data-dark-src="/assets/figure-svg/figures/e1a5af06e1cd8300e6828bb2.json" data-src="/assets/figure-svg/figures/685220895e6e00b6fe6549d5.json" style=";--figure-ratio:960.0/540.0"><object data="/ko/chapter_data_structure/classification_of_data_structure.assets/computer_memory_location.svg" data-theme="light" tabindex="-1" type="image/svg+xml">메모리 모듈, 메모리 공간, 메모리 주소</object><object data="/ko/chapter_data_structure/classification_of_data_structure.assets/computer_memory_location.dark.svg" data-theme="dark" tabindex="-1" type="image/svg+xml">메모리 모듈, 메모리 공간, 메모리 주소</object></ha-svg-figure></p>
|
||||
<p align="center"> 그림 3-2 메모리 모듈, 메모리 공간, 메모리 주소 </p>
|
||||
<p><ha-svg-figure aria-label="주소로 메모리에 접근하기" class="animation-figure" data-book-key="ko/chapter_data_structure/classification_of_data_structure.assets/computer_memory_location.png" data-dark-src="/assets/figure-svg/figures/e1a5af06e1cd8300e6828bb2.json" data-figure-accessible="" data-src="/assets/figure-svg/figures/685220895e6e00b6fe6549d5.json" role="img" style=";--figure-ratio:960.0/540.0"><object aria-hidden="true" data="/ko/chapter_data_structure/classification_of_data_structure.assets/computer_memory_location.svg" data-theme="light" inert="" tabindex="-1" type="image/svg+xml">메모리 모듈, 메모리 공간, 메모리 주소</object><object aria-hidden="true" data="/ko/chapter_data_structure/classification_of_data_structure.assets/computer_memory_location.dark.svg" data-theme="dark" inert="" tabindex="-1" type="image/svg+xml">메모리 모듈, 메모리 공간, 메모리 주소</object></ha-svg-figure></p>
|
||||
<p align="center"> 그림 3-2 메모리 모듈, 메모리 공간, 메모리 주소 </p><div class="ha-sr-only figure-description"><h3>그림 3-2 설명: 주소로 메모리에 접근하기</h3><p>행 시작 주소에 열 오프셋을 더해 메모리 셀의 위치를 찾고 저장된 데이터를 읽는다.</p><p>왼쪽에는 세로로 놓인 메모리 모듈이 있고, 검은색 칩 영역에서 뻗어 나온 두 회색 선이 오른쪽의 메모리 공간 격자로 이어진다. 이 칩들은 격자 안에서 ‘사용 중인 메모리’를 뜻하는 짙은 색 셀과 같은 층위의 개념이 아니다.</p><p>격자는 5행 8열로 그려져 있으며, 행 시작 주소는 0x0000, 0x0010, 0x0020, 0x0030, 0x0040이고 열 오프셋은 00부터 07까지다. 오른쪽과 아래쪽의 말줄임표는 그림에 생략된 셀이 더 있음을 뜻한다. 밝은 색은 사용 가능한 메모리, 짙은 색은 사용 중인 메모리이며, 사용 가능하다는 것이 그 안에 값 0이 들어 있다는 뜻은 아니다.</p><table><caption>그림 속 사용 중인 메모리 셀 두 곳</caption><thead><tr><th scope="col">전체 주소</th><th scope="col">행 시작 주소</th><th scope="col">열 오프셋</th><th scope="col">저장된 데이터</th></tr></thead><tbody><tr><th scope="row">0x0012</th><td>0x0010</td><td>02</td><td>1</td></tr><tr><th scope="row">0x0024</th><td>0x0020</td><td>04</td><td>2</td></tr></tbody></table><p>행 시작 주소에 열 오프셋을 더하면 셀 위치를 바로 찾을 수 있다. 예를 들어 0x0020에 오프셋 04를 더하면 0x0024가 되고, 여기서 데이터 2를 읽어 낸다. 격자 아래쪽의 두 접근 예시는 표의 두 행과 대응한다. 주소는 위치를 식별하고 데이터는 그 위치에 담긴 내용이며, 격자는 주소 지정 원리를 보여 주는 모식도일 뿐 칩의 실제 회로 배치를 나타내지는 않는다.</p></div>
|
||||
<div class="admonition tip">
|
||||
<p class="admonition-title">참고</p>
|
||||
<p>메모리를 Excel 표에 빗댄 것은 단순화한 비유다. 실제 메모리의 작동 방식은 더 복잡하며 주소 공간, 메모리 관리, 캐시, 가상 메모리, 물리 메모리 등의 개념이 관련된다.</p>
|
||||
</div>
|
||||
<p>메모리는 모든 프로그램이 공유하는 자원이다. 어떤 메모리 영역을 한 프로그램이 사용하면 보통 다른 프로그램은 동시에 사용할 수 없다. <strong>따라서 자료 구조와 알고리즘을 설계할 때 메모리 자원은 중요한 고려 사항이다</strong>. 예를 들어 알고리즘의 최대 메모리 사용량은 시스템의 남은 메모리를 넘지 않아야 한다. 연속된 큰 메모리 공간이 부족하다면 분산된 메모리 공간에 저장할 수 있는 자료 구조를 선택해야 한다.</p>
|
||||
<p>아래 그림(3-3)과 같이 <strong>물리적 구조는 데이터가 컴퓨터 메모리에 저장되는 방식을 나타내며</strong>, 연속 공간 저장(배열)과 분산 공간 저장(연결 리스트)으로 나뉜다. 물리적 구조는 데이터 접근, 갱신, 삽입, 삭제 등의 연산 방식을 근본적으로 결정한다. 두 물리적 구조는 시간 효율과 공간 효율에서 서로 보완적인 특징을 지닌다.</p>
|
||||
<p><ha-svg-figure class="animation-figure" data-book-key="ko/chapter_data_structure/classification_of_data_structure.assets/classification_phisical_structure.png" data-dark-src="/assets/figure-svg/figures/c8968f43f60d50708087b6b0.json" data-src="/assets/figure-svg/figures/355714d1c047ede40ea0b236.json" style=";--figure-ratio:960.0/540.0"><object data="/ko/chapter_data_structure/classification_of_data_structure.assets/classification_phisical_structure.svg" data-theme="light" tabindex="-1" type="image/svg+xml">연속 공간 저장과 분산 공간 저장</object><object data="/ko/chapter_data_structure/classification_of_data_structure.assets/classification_phisical_structure.dark.svg" data-theme="dark" tabindex="-1" type="image/svg+xml">연속 공간 저장과 분산 공간 저장</object></ha-svg-figure></p>
|
||||
<p align="center"> 그림 3-3 연속 공간 저장과 분산 공간 저장 </p>
|
||||
<p><ha-svg-figure aria-label="배열과 연결 리스트의 메모리 배치" class="animation-figure" data-book-key="ko/chapter_data_structure/classification_of_data_structure.assets/classification_phisical_structure.png" data-dark-src="/assets/figure-svg/figures/c8968f43f60d50708087b6b0.json" data-figure-accessible="" data-src="/assets/figure-svg/figures/355714d1c047ede40ea0b236.json" role="img" style=";--figure-ratio:960.0/540.0"><object aria-hidden="true" data="/ko/chapter_data_structure/classification_of_data_structure.assets/classification_phisical_structure.svg" data-theme="light" inert="" tabindex="-1" type="image/svg+xml">연속 공간 저장과 분산 공간 저장</object><object aria-hidden="true" data="/ko/chapter_data_structure/classification_of_data_structure.assets/classification_phisical_structure.dark.svg" data-theme="dark" inert="" tabindex="-1" type="image/svg+xml">연속 공간 저장과 분산 공간 저장</object></ha-svg-figure></p>
|
||||
<p align="center"> 그림 3-3 연속 공간 저장과 분산 공간 저장 </p><div class="ha-sr-only figure-description"><h3>그림 3-3 설명: 배열과 연결 리스트의 메모리 배치</h3><p>같은 논리적 수열을 연속된 공간에 저장할 수도 있고, 흩어진 노드를 포인터로 연결해 표현할 수도 있다.</p><p>왼쪽과 오른쪽 모두 5행 6열의 모식 격자이며, 행은 위에서 아래로, 열은 왼쪽에서 오른쪽으로 모두 1부터 번호를 매긴다. 왼쪽 배열은 2행의 앞쪽 5칸에 1, 3, 2, 5, 4를 연속해서 저장한다. 오른쪽 연결 리스트의 노드는 격자 곳곳에 분산되어 있으며, 각 노드는 서로 이웃한 값 칸과 포인터 칸을 차지한다.</p><p>밝은 회색 칸은 사용 가능한 메모리이고, 배열이 차지한 칸은 초록색, 연결 리스트의 값 칸은 청록색, 포인터 칸은 하늘색이다. 아래 표는 연결 리스트의 방문 순서에 따라 각 노드의 위치를 나열한다.</p><table><caption>연결 리스트 노드의 격자 위치와 다음 노드(행·열은 1부터 시작)</caption><thead><tr><th scope="col">노드 값</th><th scope="col">값 칸 위치</th><th scope="col">포인터 칸 위치</th><th scope="col">다음 노드</th></tr></thead><tbody><tr><th scope="row">1</th><td>2행 2열</td><td>2행 3열</td><td>3</td></tr><tr><th scope="row">3</th><td>3행 3열</td><td>3행 4열</td><td>2</td></tr><tr><th scope="row">2</th><td>5행 2열</td><td>5행 3열</td><td>5</td></tr><tr><th scope="row">5</th><td>5행 5열</td><td>5행 6열</td><td>4</td></tr><tr><th scope="row">4</th><td>1행 5열</td><td>1행 6열</td><td>후속 화살표 없음</td></tr></tbody></table><p>배열의 앞뒤 순서는 인접한 위치로 나타나고, 연결 리스트는 다음 노드를 가리키는 포인터를 따라 방문한다. 따라서 노드 4는 가장 위쪽 행에 놓여 있더라도 1 → 3 → 2 → 5 → 4의 맨 마지막에 위치한다. 그림에는 이 마지막 노드의 구체적인 포인터 값이 적혀 있지 않다. 연속 저장은 원소마다 다음 포인터를 따로 저장할 필요가 없고, 분산 노드는 자투리 공간을 활용할 수 있지만 포인터를 추가로 저장해야 한다.</p></div>
|
||||
<p><strong>모든 자료 구조는 배열, 연결 리스트 또는 둘의 조합으로 구현된다</strong>는 점도 알아 두자. 예를 들어 스택과 큐는 배열이나 연결 리스트로 구현할 수 있으며, 해시 테이블 구현에는 배열과 연결 리스트가 함께 포함될 수 있다.</p>
|
||||
<ul>
|
||||
<li><strong>배열로 구현할 수 있는 것</strong>: 스택, 큐, 해시 테이블, 트리, 힙, 그래프, 행렬, 텐서(차원이 <span class="arithmatex">\(\geq 3\)</span>인 배열) 등.</li>
|
||||
@@ -2065,5 +2065,5 @@
|
||||
<script src="../../javascripts/mathjax.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.min.js"></script>
|
||||
<script src="../../javascripts/animation_player.js"></script>
|
||||
<script defer="" src="/assets/figure-svg/js/bcdea376f01bc2bc0cac7c6c.js"></script><script defer="" src="/assets/figure-svg/js/e84f59519170c0f5ef238548.js"></script><script defer="" src="/assets/figure-svg/js/a704d8e80a80ddc71f2a03a7.js"></script><script defer="" src="/assets/figure-svg/js/bff17b8259339758cb1c4a06.js"></script></body>
|
||||
<script defer="" src="/assets/figure-svg/js/00174ff861e190f5c1f09e34.js"></script><script defer="" src="/assets/figure-svg/js/e84f59519170c0f5ef238548.js"></script><script defer="" src="/assets/figure-svg/js/a704d8e80a80ddc71f2a03a7.js"></script><script defer="" src="/assets/figure-svg/js/70ae82c6406c9bdbda8e8362.js"></script></body>
|
||||
</html>
|
||||
Binary file not shown.
Reference in New Issue
Block a user