mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-25 23:46:29 +08:00
build
This commit is contained in:
parent
6ad9dfd575
commit
9701430089
4 changed files with 51 additions and 14 deletions
|
@ -4,7 +4,7 @@ comments: true
|
|||
|
||||
# 2.2 迭代与递归
|
||||
|
||||
在数据结构与算法中,重复执行某个任务是很常见的,其与算法的复杂度密切相关。而要重复执行某个任务,我们通常会选用两种基本的程序结构:迭代和递归。
|
||||
在算法中,重复执行某个任务是很常见的,其与复杂度分析息息相关。因此,在展开介绍时间复杂度和空间复杂度之前,我们先来了解如何在程序中实现重复执行任务,即两种基本的程序控制结构:迭代、递归。
|
||||
|
||||
## 2.2.1 迭代
|
||||
|
||||
|
|
|
@ -20,27 +20,28 @@ comments: true
|
|||
- 整数类型 `byte` 占用 $1$ byte = $8$ bits ,可以表示 $2^{8}$ 个数字。
|
||||
- 整数类型 `int` 占用 $4$ bytes = $32$ bits ,可以表示 $2^{32}$ 个数字。
|
||||
|
||||
表 3-1 列举了各种基本数据类型的占用空间、取值范围和默认值。此表格无须硬背,大致理解即可,需要时可以通过查表来回忆。
|
||||
表 3-1 列举了 Java 中各种基本数据类型的占用空间、取值范围和默认值。此表格无须硬背,大致理解即可,需要时可以通过查表来回忆。
|
||||
|
||||
<p align="center"> 表 3-1 基本数据类型的占用空间和取值范围 </p>
|
||||
|
||||
<div class="center-table" markdown>
|
||||
|
||||
| 类型 | 符号 | 占用空间 | 最小值 | 最大值 | 默认值 |
|
||||
| ------ | -------- | ---------------- | ------------------------ | ----------------------- | -------------- |
|
||||
| 整数 | `byte` | 1 byte | $-2^7$ ($-128$) | $2^7 - 1$ ($127$) | $0$ |
|
||||
| | `short` | 2 bytes | $-2^{15}$ | $2^{15} - 1$ | $0$ |
|
||||
| | `int` | 4 bytes | $-2^{31}$ | $2^{31} - 1$ | $0$ |
|
||||
| | `long` | 8 bytes | $-2^{63}$ | $2^{63} - 1$ | $0$ |
|
||||
| 浮点数 | `float` | 4 bytes | $1.175 \times 10^{-38}$ | $3.403 \times 10^{38}$ | $0.0 f$ |
|
||||
| | `double` | 8 bytes | $2.225 \times 10^{-308}$ | $1.798 \times 10^{308}$ | $0.0$ |
|
||||
| 字符 | `char` | 2 bytes / 1 byte | $0$ | $2^{16} - 1$ | $0$ |
|
||||
| 布尔 | `bool` | 1 byte | $\text{false}$ | $\text{true}$ | $\text{false}$ |
|
||||
| 类型 | 符号 | 占用空间 | 最小值 | 最大值 | 默认值 |
|
||||
| ------ | -------- | -------- | ------------------------ | ----------------------- | -------------- |
|
||||
| 整数 | `byte` | 1 byte | $-2^7$ ($-128$) | $2^7 - 1$ ($127$) | $0$ |
|
||||
| | `short` | 2 bytes | $-2^{15}$ | $2^{15} - 1$ | $0$ |
|
||||
| | `int` | 4 bytes | $-2^{31}$ | $2^{31} - 1$ | $0$ |
|
||||
| | `long` | 8 bytes | $-2^{63}$ | $2^{63} - 1$ | $0$ |
|
||||
| 浮点数 | `float` | 4 bytes | $1.175 \times 10^{-38}$ | $3.403 \times 10^{38}$ | $0.0f$ |
|
||||
| | `double` | 8 bytes | $2.225 \times 10^{-308}$ | $1.798 \times 10^{308}$ | $0.0$ |
|
||||
| 字符 | `char` | 2 bytes | $0$ | $2^{16} - 1$ | $0$ |
|
||||
| 布尔 | `bool` | 1 byte | $\text{false}$ | $\text{true}$ | $\text{false}$ |
|
||||
|
||||
</div>
|
||||
|
||||
对于表 3-1 ,需要注意以下几点。
|
||||
请注意,表 3-1 针对的是 Java 的基本数据类型的情况。每种编程语言有各自的数据类型定义,它们的占用空间、取值范围和默认值可能会有所不同。
|
||||
|
||||
- 在 Python 中,整数类型 `int` 可以是任意大小,只受限于可用内存;浮点数 `float` 是双精度 64 位;没有 `char` 类型,单个字符实际上是长度为 1 的字符串 `str` 。
|
||||
- C 和 C++ 未明确规定基本数据类型大小,而因实现和平台各异。表 3-1 遵循 LP64 [数据模型](https://en.cppreference.com/w/cpp/language/types#Properties),其用于包括 Linux 和 macOS 在内的 Unix 64 位操作系统。
|
||||
- 字符 `char` 的大小在 C 和 C++ 中为 1 字节,在大多数编程语言中取决于特定的字符编码方法,详见“字符编码”章节。
|
||||
- 即使表示布尔量仅需 1 位($0$ 或 $1$),它在内存中通常被存储为 1 字节。这是因为现代计算机 CPU 通常将 1 字节作为最小寻址内存单元。
|
||||
|
|
|
@ -39,7 +39,7 @@ comments: true
|
|||
|
||||
数据结构与算法犹如图 1-5 所示的拼装积木。一套积木,除了包含许多零件之外,还附有详细的组装说明书。我们按照说明书一步步操作,就能组装出精美的积木模型。
|
||||
|
||||
![拼装积木](what_is_dsa.assets/assembling_blocks.jpg)
|
||||
![拼装积木](what_is_dsa.assets/assembling_blocks.png)
|
||||
|
||||
<p align="center"> 图 1-5 拼装积木 </p>
|
||||
|
||||
|
|
36
overrides/assets/images/logo.svg
Normal file
36
overrides/assets/images/logo.svg
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg id="Layer_2" data-name="Layer 2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 122.48 59.28">
|
||||
<defs>
|
||||
<style>
|
||||
.cls-1 {
|
||||
fill: #2aa996;
|
||||
}
|
||||
|
||||
.cls-1, .cls-2 {
|
||||
stroke-width: 0px;
|
||||
}
|
||||
|
||||
.cls-2 {
|
||||
fill: #21c8b8;
|
||||
}
|
||||
</style>
|
||||
</defs>
|
||||
<g id="_layer_1" data-name="layer 1">
|
||||
<path class="cls-2" d="m5.02,34.2c-1.67,8.36-3.34,16.72-5.02,25.08h5.02c1.67-8.36,3.34-16.72,5.02-25.08h-5.02Z"/>
|
||||
<path class="cls-2" d="m25.22,49.25c.33-1.67.67-3.34,1-5.02H9.07c-.33,1.67-.67,3.34-1,5.02h17.16Z"/>
|
||||
<path class="cls-2" d="m30.16,54.27c.33-1.67.67-3.34,1-5.02h7.05c.33-1.67.67-3.34,1-5.02h-7.05c.33-1.67.67-3.34,1-5.02h7.05c.33-1.67.67-3.34,1-5.02-4.02,0-8.04,0-12.06,0-1.67,8.36-3.34,16.72-5.02,25.08,4.03,0,8.06,0,12.09,0,.33-1.67.67-3.34,1-5.02h-7.07Z"/>
|
||||
<path class="cls-2" d="m93.39,34.2h-16.56s0,0,0,0c-.01.04-.92.05-3.5,0-1.67,8.36-3.34,16.72-5.02,25.08h20.07c1.67-8.36,3.34-16.72,5.02-25.08Zm-19.06,20.07c1-5.02,2.01-10.03,3.01-15.05h10.03c-1,5.02-2.01,10.03-3.01,15.05h-10.03Z"/>
|
||||
<path class="cls-2" d="m44.23,54.27h0c1.34-6.69,2.68-13.38,4.01-20.07h-5.02c-1.67,8.36-3.34,16.72-5.02,25.08h4.01c3.02,0,6.04,0,9.06,0,.33-1.67.67-3.34,1-5.02h-8.05Z"/>
|
||||
<path class="cls-2" d="m59.29,54.27h0c1.34-6.69,2.68-13.38,4.01-20.07h-5.02c-1.67,8.36-3.34,16.72-5.02,25.08,4.36,0,8.71,0,13.07,0,.33-1.67.67-3.34,1-5.02h-8.05Z"/>
|
||||
<path class="cls-1" d="m16.89.07h-5.02c-1,5.02-2.01,10.03-3.01,15.05h5.01c1-5.02,2.01-10.03,3.01-15.05Z"/>
|
||||
<path class="cls-1" d="m34.32,33.21c1.14-5.69,2.27-11.38,3.41-17.07H8.65c-1.13,5.69-2.27,11.38-3.4,17.07h29.07Zm-21.64-12.06h19.03c-.07.34-.13.67-.2,1.01H12.48c.07-.34.13-.67.2-1.01Zm-1.21,6.03h19.03c-.07.34-.13.67-.2,1.01H11.27c.07-.34.13-.67.2-1.01Z"/>
|
||||
<path class="cls-1" d="m28.93,15.12c1-5.02,2.01-10.03,3.01-15.05h-5.02c-1,5.02-2.01,10.03-3.01,15.05h5.01Z"/>
|
||||
<path class="cls-1" d="m24.92,5.09c.33-1.67.67-3.34,1-5.02h-8.03c-.33,1.67-.67,3.34-1,5.02h8.03Z"/>
|
||||
<path class="cls-1" d="m121.48,15.04s.5-2.49.5-2.51c.17-.84.33-1.67.5-2.51h-11.33c.66-3.34,1.33-6.68,1.99-10.02h-5.02c-.67,3.34-1.34,6.68-2,10.02h-7.02c-.33,1.67-.67,3.34-1,5.02h7.03s0,0,0,.01h.01c-.07.33-.13.67-.2,1h-7.07c-.33,1.67-.67,3.34-1,5.02h4.25c-2.57,12.74-5.14,25.48-7.7,38.22,6.4,0,12.8,0,19.21,0l5.07-25.08h-5.03c-1.35,6.69-2.71,13.38-4.06,20.07h-9.13c2.22-11.07,4.44-22.13,6.66-33.2h14.1c.33-1.67.67-3.34,1-5.02h-11.28c.07-.34.13-.67.2-1.01h11.33Z"/>
|
||||
<path class="cls-1" d="m16.87,6.12c.6,3,1.2,6,1.8,9h4.23c-.6-3-1.2-6-1.8-9h-4.24Z"/>
|
||||
<path class="cls-1" d="m97,16.06h-5.02c-1.13,5.69-2.27,11.38-3.4,17.06h5.01c1.13-5.69,2.27-11.38,3.4-17.06Z"/>
|
||||
<path class="cls-1" d="m100.2,0h-5.02c-1,5.02-2.01,10.03-3.01,15.05h5.03c1-5.02,2-10.03,3-15.05Z"/>
|
||||
<path class="cls-1" d="m39.97,5.09c.33-1.67.67-3.34,1-5.02h-8.03c-.33,1.67-.67,3.34-1,5.02h8.03Z"/>
|
||||
<path class="cls-1" d="m31.92,6.12c.6,3,1.2,6,1.8,9h4.23c-.6-3-1.2-6-1.8-9h-4.24Z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.9 KiB |
Loading…
Reference in a new issue