mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-10 06:26:08 +00:00
deploy
This commit is contained in:
@@ -3311,15 +3311,15 @@
|
||||
<p>谈及计算机中的数据,我们会想到文本、图片、视频、语音、3D 模型等各种形式。尽管这些数据的组织形式各异,但它们都由各种基本数据类型构成。</p>
|
||||
<p><strong>基本数据类型是 CPU 可以直接进行运算的类型,在算法中直接被使用</strong>。它包括:</p>
|
||||
<ul>
|
||||
<li>整数类型 <code>byte</code> , <code>short</code> , <code>int</code> , <code>long</code> ;</li>
|
||||
<li>浮点数类型 <code>float</code> , <code>double</code> ,用于表示小数;</li>
|
||||
<li>字符类型 <code>char</code> ,用于表示各种语言的字母、标点符号、甚至表情符号等;</li>
|
||||
<li>布尔类型 <code>bool</code> ,用于表示“是”与“否”判断;</li>
|
||||
<li>整数类型 <code>byte</code> , <code>short</code> , <code>int</code> , <code>long</code> 。</li>
|
||||
<li>浮点数类型 <code>float</code> , <code>double</code> ,用于表示小数。</li>
|
||||
<li>字符类型 <code>char</code> ,用于表示各种语言的字母、标点符号、甚至表情符号等。</li>
|
||||
<li>布尔类型 <code>bool</code> ,用于表示“是”与“否”判断。</li>
|
||||
</ul>
|
||||
<p><strong>所有基本数据类型都以二进制的形式存储在计算机中</strong>。在计算机中,我们将 <span class="arithmatex">\(1\)</span> 个二进制位称为 <span class="arithmatex">\(1\)</span> 比特,并规定 <span class="arithmatex">\(1\)</span> 字节(byte)由 <span class="arithmatex">\(8\)</span> 比特(bits)组成。基本数据类型的取值范围取决于其占用的空间大小,例如:</p>
|
||||
<ul>
|
||||
<li>整数类型 <code>byte</code> 占用 <span class="arithmatex">\(1\)</span> byte = <span class="arithmatex">\(8\)</span> bits ,可以表示 <span class="arithmatex">\(2^{8}\)</span> 个不同的数字;</li>
|
||||
<li>整数类型 <code>int</code> 占用 <span class="arithmatex">\(4\)</span> bytes = <span class="arithmatex">\(32\)</span> bits ,可以表示 <span class="arithmatex">\(2^{32}\)</span> 个数字;</li>
|
||||
<li>整数类型 <code>byte</code> 占用 <span class="arithmatex">\(1\)</span> byte = <span class="arithmatex">\(8\)</span> bits ,可以表示 <span class="arithmatex">\(2^{8}\)</span> 个不同的数字。</li>
|
||||
<li>整数类型 <code>int</code> 占用 <span class="arithmatex">\(4\)</span> bytes = <span class="arithmatex">\(32\)</span> bits ,可以表示 <span class="arithmatex">\(2^{32}\)</span> 个数字。</li>
|
||||
</ul>
|
||||
<p>下表列举了各种基本数据类型的占用空间、取值范围和默认值。此表格无需硬背,大致理解即可,需要时可以通过查表来回忆。</p>
|
||||
<div class="center-table">
|
||||
|
||||
@@ -3379,17 +3379,17 @@
|
||||
<p><strong>「逻辑结构」揭示了数据元素之间的逻辑关系</strong>。在数组和链表中,数据按照顺序依次排列,体现了数据之间的线性关系;而在树中,数据从顶部向下按层次排列,表现出祖先与后代之间的派生关系;图则由节点和边构成,反映了复杂的网络关系。</p>
|
||||
<p>逻辑结构通常分为“线性”和“非线性”两类。线性结构比较直观,指数据在逻辑关系上呈线性排列;非线性结构则相反,呈非线性排列。</p>
|
||||
<ul>
|
||||
<li><strong>线性数据结构</strong>:数组、链表、栈、队列、哈希表;</li>
|
||||
<li><strong>非线性数据结构</strong>:树、堆、图、哈希表;</li>
|
||||
<li><strong>线性数据结构</strong>:数组、链表、栈、队列、哈希表。</li>
|
||||
<li><strong>非线性数据结构</strong>:树、堆、图、哈希表。</li>
|
||||
</ul>
|
||||
<p><img alt="线性与非线性数据结构" src="../classification_of_data_structure.assets/classification_logic_structure.png" /></p>
|
||||
<p align="center"> Fig. 线性与非线性数据结构 </p>
|
||||
|
||||
<p>非线性数据结构可以进一步被划分为树形结构和网状结构。</p>
|
||||
<ul>
|
||||
<li><strong>线性结构</strong>:数组、链表、队列、栈、哈希表,元素存在一对一的顺序关系;</li>
|
||||
<li><strong>树形结构</strong>:树、堆、哈希表,元素存在一对多的关系;</li>
|
||||
<li><strong>网状结构</strong>:图,元素存在多对多的关系;</li>
|
||||
<li><strong>线性结构</strong>:数组、链表、队列、栈、哈希表,元素存在一对一的顺序关系。</li>
|
||||
<li><strong>树形结构</strong>:树、堆、哈希表,元素存在一对多的关系。</li>
|
||||
<li><strong>网状结构</strong>:图,元素存在多对多的关系。</li>
|
||||
</ul>
|
||||
<h2 id="312">3.1.2. 物理结构:连续与离散<a class="headerlink" href="#312" title="Permanent link">¶</a></h2>
|
||||
<p>在计算机中,内存和硬盘是两种主要的存储硬件设备。硬盘主要用于长期存储数据,容量较大(通常可达到 TB 级别)、速度较慢。内存用于运行程序时暂存数据,速度较快,但容量较小(通常为 GB 级别)。</p>
|
||||
@@ -3405,8 +3405,8 @@
|
||||
|
||||
<p><strong>所有数据结构都是基于数组、链表或二者的组合实现的</strong>。例如,栈和队列既可以使用数组实现,也可以使用链表实现;而哈希表的实现可能同时包含数组和链表。</p>
|
||||
<ul>
|
||||
<li><strong>基于数组可实现</strong>:栈、队列、哈希表、树、堆、图、矩阵、张量(维度 <span class="arithmatex">\(\geq 3\)</span> 的数组)等;</li>
|
||||
<li><strong>基于链表可实现</strong>:栈、队列、哈希表、树、堆、图等;</li>
|
||||
<li><strong>基于数组可实现</strong>:栈、队列、哈希表、树、堆、图、矩阵、张量(维度 <span class="arithmatex">\(\geq 3\)</span> 的数组)等。</li>
|
||||
<li><strong>基于链表可实现</strong>:栈、队列、哈希表、树、堆、图等。</li>
|
||||
</ul>
|
||||
<p>基于数组实现的数据结构也被称为“静态数据结构”,这意味着此类数据结构在初始化后长度不可变。相对应地,基于链表实现的数据结构被称为“动态数据结构”,这类数据结构在初始化后,仍可以在程序运行过程中对其长度进行调整。</p>
|
||||
<div class="admonition tip">
|
||||
|
||||
@@ -3445,9 +3445,9 @@
|
||||
<p>细心的你可能会发现:<code>int</code> 和 <code>float</code> 长度相同,都是 4 bytes,但为什么 <code>float</code> 的取值范围远大于 <code>int</code> ?这非常反直觉,因为按理说 <code>float</code> 需要表示小数,取值范围应该变小才对。</p>
|
||||
<p>实际上,这是因为浮点数 <code>float</code> 采用了不同的表示方式。根据 IEEE 754 标准,32-bit 长度的 <code>float</code> 由以下部分构成:</p>
|
||||
<ul>
|
||||
<li>符号位 <span class="arithmatex">\(\mathrm{S}\)</span> :占 1 bit ;</li>
|
||||
<li>指数位 <span class="arithmatex">\(\mathrm{E}\)</span> :占 8 bits ;</li>
|
||||
<li>分数位 <span class="arithmatex">\(\mathrm{N}\)</span> :占 24 bits ,其中 23 位显式存储;</li>
|
||||
<li>符号位 <span class="arithmatex">\(\mathrm{S}\)</span> :占 1 bit 。</li>
|
||||
<li>指数位 <span class="arithmatex">\(\mathrm{E}\)</span> :占 8 bits 。</li>
|
||||
<li>分数位 <span class="arithmatex">\(\mathrm{N}\)</span> :占 24 bits ,其中 23 位显式存储。</li>
|
||||
</ul>
|
||||
<p>设 32-bit 二进制数的第 <span class="arithmatex">\(i\)</span> 位为 <span class="arithmatex">\(b_i\)</span> ,则 <code>float</code> 值的计算方法定义为:</p>
|
||||
<div class="arithmatex">\[
|
||||
@@ -3508,8 +3508,8 @@
|
||||
</div>
|
||||
<p>特别地,次正规数显著提升了浮点数的精度,这是因为:</p>
|
||||
<ul>
|
||||
<li>最小正正规数为 <span class="arithmatex">\(2^{-126} \approx 1.18 \times 10^{-38}\)</span> ;</li>
|
||||
<li>最小正次正规数为 <span class="arithmatex">\(2^{-126} \times 2^{-23} \approx 1.4 \times 10^{-45}\)</span> ;</li>
|
||||
<li>最小正正规数为 <span class="arithmatex">\(2^{-126} \approx 1.18 \times 10^{-38}\)</span> 。</li>
|
||||
<li>最小正次正规数为 <span class="arithmatex">\(2^{-126} \times 2^{-23} \approx 1.4 \times 10^{-45}\)</span> 。</li>
|
||||
</ul>
|
||||
<p>双精度 <code>double</code> 也采用类似 <code>float</code> 的表示方法,此处不再详述。</p>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user