Release reviewed gh-pages candidate

This commit is contained in:
krahets
2026-11-18 16:34:49 +08:00
parent 8966617032
commit 451a6b692c
822 changed files with 3585 additions and 3541 deletions

View File

@@ -1925,21 +1925,21 @@
<li><strong>Tree structures</strong>: Trees, heaps, and hash tables, with one-to-many relationships.</li>
<li><strong>Network structures</strong>: Graphs, with many-to-many relationships.</li>
</ul>
<p><ha-svg-figure class="animation-figure" data-book-key="en/chapter_data_structure/classification_of_data_structure.assets/classification_logic_structure.png" data-dark-src="/assets/figure-svg/figures/9056b2ea875e6394b2052cad.json" data-src="/assets/figure-svg/figures/5297bc40e40f314e280c3bbd.json" style=";--figure-ratio:960.0/540.0"><object data="/en/chapter_data_structure/classification_of_data_structure.assets/classification_logic_structure.svg" data-theme="light" tabindex="-1" type="image/svg+xml">Linear and nonlinear data structures</object><object data="/en/chapter_data_structure/classification_of_data_structure.assets/classification_logic_structure.dark.svg" data-theme="dark" tabindex="-1" type="image/svg+xml">Linear and nonlinear data structures</object></ha-svg-figure></p>
<p align="center"> Figure 3-1   Linear and nonlinear data structures </p>
<p><ha-svg-figure aria-label="Logical relationships in data structures" class="animation-figure" data-book-key="en/chapter_data_structure/classification_of_data_structure.assets/classification_logic_structure.png" data-dark-src="/assets/figure-svg/figures/9056b2ea875e6394b2052cad.json" data-figure-accessible="" data-src="/assets/figure-svg/figures/5297bc40e40f314e280c3bbd.json" role="img" style=";--figure-ratio:960.0/540.0"><object aria-hidden="true" data="/en/chapter_data_structure/classification_of_data_structure.assets/classification_logic_structure.svg" data-theme="light" inert="" tabindex="-1" type="image/svg+xml">Linear and nonlinear data structures</object><object aria-hidden="true" data="/en/chapter_data_structure/classification_of_data_structure.assets/classification_logic_structure.dark.svg" data-theme="dark" inert="" tabindex="-1" type="image/svg+xml">Linear and nonlinear data structures</object></ha-svg-figure></p>
<p align="center"> Figure 3-1   Linear and nonlinear data structures </p><div class="ha-sr-only figure-description"><h3>Description of Figure 3-1: Logical relationships in data structures</h3><p>Compare four kinds of logical relationships: sequential order, parent-child hierarchy, network connections, and key-value mapping.</p><p>The left column of the figure groups linear data structures, and the right column groups nonlinear data structures; the hash table spans across the bottom beneath both columns to illustrate key-value mapping separately.</p><table><caption>Examples and connections for each data structure</caption><thead><tr><th scope="col">Structure</th><th scope="col">Column in figure</th><th scope="col">Elements and relationships shown</th></tr></thead><tbody><tr><th scope="row">Array</th><td>Linear</td><td>Arranged in order 1, 3, 2, 5, 4</td></tr><tr><th scope="row">Linked list</th><td>Linear</td><td>1→3→2→5→4</td></tr><tr><th scope="row">Stack</th><td>Linear</td><td>1, 3, 2, 5, 4 from the open end to the closed end; both push and pop occur at the open end</td></tr><tr><th scope="row">Queue</th><td>Linear</td><td>1, 3, 2, 5, 4 from the dequeue end to the enqueue end; push (enqueue) and pop (dequeue) occur at opposite ends</td></tr><tr><th scope="row">Tree</th><td>Nonlinear</td><td>Root 1 with left child 2 and right child 3; 2 has left 4 and right 5; 3 has left 6 and right 7; 7 nodes across three levels</td></tr><tr><th scope="row">Graph</th><td>Nonlinear</td><td>5 vertices 1 through 5; 7 undirected edges: 1—2, 1—3, 2—3, 2—4, 2—5, 3—5, 4—5</td></tr><tr><th scope="row">Heap</th><td>Nonlinear</td><td>Root 1 with left child 3 and right child 2; 3 has left 5 and right 4; 5 nodes across three levels</td></tr><tr><th scope="row">Hash table</th><td>Full-width row across both columns</td><td>Keys a, b, and c map to values 1, 2, and 3, respectively</td></tr></tbody></table><p>Linear structures maintain a sequential order while differing in where operations are permitted; trees and heaps organize parent-child hierarchies, and graphs allow a vertex to connect to multiple neighbors. What is compared here is logical structure rather than underlying physical storage: the same logical relationship can be implemented in different ways, and a hash table can combine arrays, linked lists, or trees.</p></div>
<h2 id="312-physical-structure-contiguous-and-scattered-storage">3.1.2   Physical structure: contiguous and scattered storage<a class="headerlink" href="#312-physical-structure-contiguous-and-scattered-storage" title="Permanent link"></a></h2>
<p><strong>While an algorithm runs, the data it processes is mainly stored in memory</strong>. Figure 3-2 shows a memory module, with each black chip containing storage space. We can imagine memory as a huge Excel spreadsheet, where each cell holds a certain amount of data.</p>
<p><strong>The system uses memory addresses to access data at particular locations</strong>. As shown in Figure 3-2, the computer assigns each cell a number according to specific rules, giving every memory location a unique address. Programs use these addresses to access data.</p>
<p><ha-svg-figure class="animation-figure" data-book-key="en/chapter_data_structure/classification_of_data_structure.assets/computer_memory_location.png" data-dark-src="/assets/figure-svg/figures/e3395bb0829e9ac302fd1897.json" data-src="/assets/figure-svg/figures/e78e6e6d0ec6973e0399210e.json" style=";--figure-ratio:960.0/540.0"><object data="/en/chapter_data_structure/classification_of_data_structure.assets/computer_memory_location.svg" data-theme="light" tabindex="-1" type="image/svg+xml">Memory module, storage space, and memory addresses</object><object data="/en/chapter_data_structure/classification_of_data_structure.assets/computer_memory_location.dark.svg" data-theme="dark" tabindex="-1" type="image/svg+xml">Memory module, storage space, and memory addresses</object></ha-svg-figure></p>
<p align="center"> Figure 3-2   Memory module, storage space, and memory addresses </p>
<p><ha-svg-figure aria-label="Accessing memory by address" class="animation-figure" data-book-key="en/chapter_data_structure/classification_of_data_structure.assets/computer_memory_location.png" data-dark-src="/assets/figure-svg/figures/e3395bb0829e9ac302fd1897.json" data-figure-accessible="" data-src="/assets/figure-svg/figures/e78e6e6d0ec6973e0399210e.json" role="img" style=";--figure-ratio:960.0/540.0"><object aria-hidden="true" data="/en/chapter_data_structure/classification_of_data_structure.assets/computer_memory_location.svg" data-theme="light" inert="" tabindex="-1" type="image/svg+xml">Memory module, storage space, and memory addresses</object><object aria-hidden="true" data="/en/chapter_data_structure/classification_of_data_structure.assets/computer_memory_location.dark.svg" data-theme="dark" inert="" tabindex="-1" type="image/svg+xml">Memory module, storage space, and memory addresses</object></ha-svg-figure></p>
<p align="center"> Figure 3-2   Memory module, storage space, and memory addresses </p><div class="ha-sr-only figure-description"><h3>Description of Figure 3-2: Accessing memory by address</h3><p>Locate a memory cell by adding its row base address and column offset, then read the data stored there.</p><p>On the left is a vertical memory module whose black chip area connects via two gray lines to the memory grid on the right. Those physical chips are not at the same level of representation as the dark cells indicating used memory inside the grid.</p><p>The grid shows 5 rows and 8 columns: row base addresses are 0x0000, 0x0010, 0x0020, 0x0030, and 0x0040, and column offsets run from 00 to 07; ellipses on the right and bottom indicate additional cells not drawn. Light cells represent free memory and dark cells represent used memory; free memory does not mean the cell contains the number 0.</p><table><caption>Two used memory cells highlighted in the figure</caption><thead><tr><th scope="col">Full address</th><th scope="col">Row base address</th><th scope="col">Column offset</th><th scope="col">Stored data</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>Adding the row base address and column offset pinpoints a cell. For example, 0x0020 plus offset 04 gives 0x0024, yielding data value 2. The two read callouts below the grid correspond to the two rows in the table. An address identifies a location, whereas data is the content stored at that location; the grid is an addressing diagram rather than the physical circuit layout of a memory chip.</p></div>
<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>The Excel spreadsheet analogy is a simplification. Real memory is more complex and involves address spaces, memory management, caching, virtual memory, and physical memory.</p>
</div>
<p>Memory is a resource used by all programs. When a program occupies a region of memory, other programs usually cannot use that region at the same time. <strong>Memory resources are therefore an important consideration when designing data structures and algorithms</strong>. For example, an algorithm's peak memory usage should not exceed the system's available memory. If no large contiguous region is available, the chosen data structure must support scattered storage.</p>
<p>As shown in Figure 3-3, <strong>physical structure describes how data is stored in computer memory</strong>: either contiguously (arrays) or in scattered locations (linked lists). It determines how data can be accessed, updated, inserted, and deleted. The two storage forms have complementary strengths in time and space efficiency.</p>
<p><ha-svg-figure class="animation-figure" data-book-key="en/chapter_data_structure/classification_of_data_structure.assets/classification_phisical_structure.png" data-dark-src="/assets/figure-svg/figures/07adfae82368b9408a60cbfa.json" data-src="/assets/figure-svg/figures/4155fe3b8fac8773d747e09f.json" style=";--figure-ratio:960.0/540.0"><object data="/en/chapter_data_structure/classification_of_data_structure.assets/classification_phisical_structure.svg" data-theme="light" tabindex="-1" type="image/svg+xml">Contiguous and scattered storage</object><object data="/en/chapter_data_structure/classification_of_data_structure.assets/classification_phisical_structure.dark.svg" data-theme="dark" tabindex="-1" type="image/svg+xml">Contiguous and scattered storage</object></ha-svg-figure></p>
<p align="center"> Figure 3-3   Contiguous and scattered storage </p>
<p><ha-svg-figure aria-label="Storage layout of arrays and linked lists" class="animation-figure" data-book-key="en/chapter_data_structure/classification_of_data_structure.assets/classification_phisical_structure.png" data-dark-src="/assets/figure-svg/figures/07adfae82368b9408a60cbfa.json" data-figure-accessible="" data-src="/assets/figure-svg/figures/4155fe3b8fac8773d747e09f.json" role="img" style=";--figure-ratio:960.0/540.0"><object aria-hidden="true" data="/en/chapter_data_structure/classification_of_data_structure.assets/classification_phisical_structure.svg" data-theme="light" inert="" tabindex="-1" type="image/svg+xml">Contiguous and scattered storage</object><object aria-hidden="true" data="/en/chapter_data_structure/classification_of_data_structure.assets/classification_phisical_structure.dark.svg" data-theme="dark" inert="" tabindex="-1" type="image/svg+xml">Contiguous and scattered storage</object></ha-svg-figure></p>
<p align="center"> Figure 3-3   Contiguous and scattered storage </p><div class="ha-sr-only figure-description"><h3>Description of Figure 3-3: Storage layout of arrays and linked lists</h3><p>The same logical sequence can be stored contiguously or linked via pointers across noncontiguous nodes.</p><p>Both the left and right panels show schematic 5-by-6 memory grids, with rows numbered from top to bottom and columns from left to right, both starting at 1. On the left, the array stores 1, 3, 2, 5, 4 contiguously in the first 5 cells of row 2; on the right, linked list nodes are scattered across the grid, with each node occupying an adjacent value cell and pointer cell.</p><p>Light gray cells represent free memory; cells storing the array are green, while in the linked list, value cells are cyan and pointer cells are light blue. The table below lists each node's grid location in linked-list traversal order.</p><table><caption>Schematic grid locations and successors of linked list nodes (1-based rows and columns)</caption><thead><tr><th scope="col">Node value</th><th scope="col">Value cell</th><th scope="col">Pointer cell</th><th scope="col">Successor</th></tr></thead><tbody><tr><th scope="row">1</th><td>Row 2, column 2</td><td>Row 2, column 3</td><td>3</td></tr><tr><th scope="row">3</th><td>Row 3, column 3</td><td>Row 3, column 4</td><td>2</td></tr><tr><th scope="row">2</th><td>Row 5, column 2</td><td>Row 5, column 3</td><td>5</td></tr><tr><th scope="row">5</th><td>Row 5, column 5</td><td>Row 5, column 6</td><td>4</td></tr><tr><th scope="row">4</th><td>Row 1, column 5</td><td>Row 1, column 6</td><td>No outgoing arrow drawn</td></tr></tbody></table><p>An array expresses sequential order through adjacent memory locations, whereas a linked list is traversed by following next pointers. Consequently, although node 4 lies in the top row, it still comes last in 1 → 3 → 2 → 5 → 4. The figure does not label its specific pointer value. Contiguous storage avoids storing an extra pointer per element; noncontiguous nodes can utilize fragmented free memory, at the cost of storing a pointer alongside each value.</p></div>
<p><strong>All data structures are implemented using arrays, linked lists, or a combination of the two</strong>. For example, stacks and queues can use either arrays or linked lists, while hash tables may use both.</p>
<ul>
<li><strong>Array-based implementations</strong>: Stacks, queues, hash tables, trees, heaps, graphs, matrices, tensors (arrays with dimension <span class="arithmatex">\(\geq 3\)</span>), and more.</li>
@@ -2071,5 +2071,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>