mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08:00
Several bug fixes and improvements (#1178)
* Update pythontutor block with the latest code * Move docs-en to en/docs * Move mkdocs.yml and README to en folder * Fix en/mkdocs.yml * Update the landing page * Fix the glossary * Reduce the font size of the code block tabs * Add Kotlin blocks to en/docs * Fix the code link in en/.../deque.md * Fix the EN README link
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 154 KiB |
50
en/docs/chapter_preface/about_the_book.md
Normal file
50
en/docs/chapter_preface/about_the_book.md
Normal file
@ -0,0 +1,50 @@
|
||||
# About This Book
|
||||
|
||||
This open-source project aims to create a free, and beginner-friendly crash course on data structures and algorithms.
|
||||
|
||||
- Using animated illustrations, it delivers structured insights into data structures and algorithmic concepts, ensuring comprehensibility and a smooth learning curve.
|
||||
- Run code with just one click, supporting Java, C++, Python, Go, JS, TS, C#, Swift, Rust, Dart, Zig and other languages.
|
||||
- Readers are encouraged to engage with each other in the discussion area for each section, questions and comments are usually answered within two days.
|
||||
|
||||
## Target Audience
|
||||
|
||||
If you are new to algorithms with limited exposure, or you have accumulated some experience in algorithms, but you only have a vague understanding of data structures and algorithms, and you are constantly jumping between "yep" and "hmm", then this book is for you!
|
||||
|
||||
If you have already accumulated a certain amount of problem-solving experience, and are familiar with most types of problems, then this book can help you review and organize your algorithm knowledge system. The repository's source code can be used as a "problem-solving toolkit" or an "algorithm cheat sheet".
|
||||
|
||||
If you are an algorithm expert, we look forward to receiving your valuable suggestions, or [join us and collaborate](https://www.hello-algo.com/chapter_appendix/contribution/).
|
||||
|
||||
!!! success "Prerequisites"
|
||||
|
||||
You should know how to write and read simple code in at least one programming language.
|
||||
|
||||
## Content Structure
|
||||
|
||||
The main content of the book is shown in the following figure.
|
||||
|
||||
- **Complexity Analysis**: explores aspects and methods for evaluating data structures and algorithms. Covers methods of deriving time complexity and space complexity, along with common types and examples.
|
||||
- **Data Structures**: focuses on fundamental data types, classification methods, definitions, pros and cons, common operations, types, applications, and implementation methods of data structures such as array, linked list, stack, queue, hash table, tree, heap, graph, etc.
|
||||
- **Algorithms**: defines algorithms, discusses their pros and cons, efficiency, application scenarios, problem-solving steps, and includes sample questions for various algorithms such as search, sorting, divide and conquer, backtracking, dynamic programming, greedy algorithms, and more.
|
||||
|
||||

|
||||
|
||||
## Acknowledgements
|
||||
|
||||
This book is continuously improved with the joint efforts of many contributors from the open-source community. Thanks to each writer who invested their time and energy, listed in the order generated by GitHub: krahets, codingonion, nuomi1, Gonglja, Reanon, justin-tse, danielsss, hpstory, S-N-O-R-L-A-X, night-cruise, msk397, gvenusleo, RiverTwilight, gyt95, zhuoqinyue, Zuoxun, Xia-Sang, mingXta, FangYuan33, GN-Yu, IsChristina, xBLACKICEx, guowei-gong, Cathay-Chen, mgisr, JoseHung, qualifier1024, pengchzn, Guanngxu, longsizhuo, L-Super, what-is-me, yuan0221, lhxsm, Slone123c, WSL0809, longranger2, theNefelibatas, xiongsp, JeffersonHuang, hongyun-robot, K3v123, yuelinxin, a16su, gaofer, malone6, Wonderdch, xjr7670, DullSword, Horbin-Magician, NI-SW, reeswell, XC-Zero, XiaChuerwu, yd-j, iron-irax, huawuque404, MolDuM, Nigh, KorsChen, foursevenlove, 52coder, bubble9um, youshaoXG, curly210102, gltianwen, fanchenggang, Transmigration-zhou, FloranceYeh, FreddieLi, ShiMaRing, lipusheng, Javesun99, JackYang-hellobobo, shanghai-Jerry, 0130w, Keynman, psychelzh, logan-qiu, ZnYang2018, MwumLi, 1ch0, Phoenix0415, qingpeng9802, Richard-Zhang1019, QiLOL, Suremotoo, Turing-1024-Lee, Evilrabbit520, GaochaoZhu, ZJKung, linzeyan, hezhizhen, ZongYangL, beintentional, czruby, coderlef, dshlstarr, szu17dmy, fbigm, gledfish, hts0000, boloboloda, iStig, jiaxianhua, wenjianmin, keshida, kilikilikid, lclc6, lwbaptx, liuxjerry, lucaswangdev, lyl625760, chadyi, noobcodemaker, selear, siqyka, syd168, 4yDX3906, tao363, wangwang105, weibk, yabo083, yi427, yishangzhang, zhouLion, baagod, ElaBosak233, xb534, luluxia, yanedie, thomasq0, YangXuanyi and th1nk3r-ing.
|
||||
|
||||
The code review work for this book was completed by codingonion, Gonglja, gvenusleo, hpstory, justin‐tse, krahets, night-cruise, nuomi1, and Reanon (listed in alphabetical order). Thanks to them for their time and effort, ensuring the standardization and uniformity of the code in various languages.
|
||||
|
||||
Throughout the creation of this book, numerous individuals provided invaluable assistance, including but not limited to:
|
||||
|
||||
- Thanks to my mentor at the company, Dr. Xi Li, who encouraged me in a conversation to "get moving fast," which solidified my determination to write this book;
|
||||
- Thanks to my girlfriend Bubble, as the first reader of this book, for offering many valuable suggestions from the perspective of a beginner in algorithms, making this book more suitable for newbies;
|
||||
- Thanks to Tengbao, Qibao, and Feibao for coming up with a creative name for this book, evoking everyone's fond memories of writing their first line of code "Hello World!";
|
||||
- Thanks to Xiaoquan for providing professional help in intellectual property, which has played a significant role in the development of this open-source book;
|
||||
- Thanks to Sutong for designing a beautiful cover and logo for this book, and for patiently making multiple revisions under my insistence;
|
||||
- Thanks to @squidfunk for providing writing and typesetting suggestions, as well as his developed open-source documentation theme [Material-for-MkDocs](https://github.com/squidfunk/mkdocs-material/tree/master).
|
||||
|
||||
Throughout the writing journey, I delved into numerous textbooks and articles on data structures and algorithms. These works served as exemplary models, ensuring the accuracy and quality of this book's content. I extend my gratitude to all who preceded me for their invaluable contributions!
|
||||
|
||||
This book advocates a combination of hands-on and minds-on learning, inspired in this regard by ["Dive into Deep Learning"](https://github.com/d2l-ai/d2l-zh). I highly recommend this excellent book to all readers.
|
||||
|
||||
**Heartfelt thanks to my parents, whose ongoing support and encouragement have allowed me to do this interesting work**.
|
||||
13
en/docs/chapter_preface/index.md
Normal file
13
en/docs/chapter_preface/index.md
Normal file
@ -0,0 +1,13 @@
|
||||
# Preface
|
||||
|
||||
<div class="center-table" markdown>
|
||||
|
||||

|
||||
|
||||
</div>
|
||||
|
||||
!!! abstract
|
||||
|
||||
Algorithms are like a beautiful symphony, with each line of code flowing like a rhythm.
|
||||
|
||||
May this book ring softly in your mind, leaving a unique and profound melody.
|
||||
BIN
en/docs/chapter_preface/suggestions.assets/code_md_to_repo.png
Normal file
BIN
en/docs/chapter_preface/suggestions.assets/code_md_to_repo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 80 KiB |
BIN
en/docs/chapter_preface/suggestions.assets/download_code.png
Normal file
BIN
en/docs/chapter_preface/suggestions.assets/download_code.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 91 KiB |
BIN
en/docs/chapter_preface/suggestions.assets/learning_route.png
Normal file
BIN
en/docs/chapter_preface/suggestions.assets/learning_route.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 72 KiB |
239
en/docs/chapter_preface/suggestions.md
Normal file
239
en/docs/chapter_preface/suggestions.md
Normal file
@ -0,0 +1,239 @@
|
||||
# How to Read
|
||||
|
||||
!!! tip
|
||||
|
||||
For the best reading experience, it is recommended that you read through this section.
|
||||
|
||||
## Writing Conventions
|
||||
|
||||
- Chapters marked with '*' after the title are optional and contain relatively challenging content. If you are short on time, it is advisable to skip them.
|
||||
- Key technical terms and their English equivalents are enclosed in **Bold** + *italics* brackets, for example, ***array***. It's advisable to familiarize yourself with these for better comprehension of technical texts.
|
||||
- Proprietary terms and words with specific meanings are indicated with “quotation marks” to avoid ambiguity.
|
||||
- **Bolded text** indicates key content or summary statements, which deserve special attention.
|
||||
- When it comes to terms that are inconsistent between programming languages, this book follows Python, for example using $\text{None}$ to mean "null".
|
||||
- This book partially ignores the comment conventions for programming languages in exchange for a more compact layout of the content. The comments primarily consist of three types: title comments, content comments, and multi-line comments.
|
||||
|
||||
=== "Python"
|
||||
|
||||
```python title=""
|
||||
"""Header comments for labeling functions, classes, test samples, etc""""
|
||||
|
||||
# Comments for explaining details
|
||||
|
||||
"""
|
||||
Multiline
|
||||
comments
|
||||
"""
|
||||
```
|
||||
|
||||
=== "C++"
|
||||
|
||||
```cpp title=""
|
||||
/* Header comments for labeling functions, classes, test samples, etc */
|
||||
|
||||
// Comments for explaining details.
|
||||
|
||||
/**
|
||||
* Multiline
|
||||
* comments
|
||||
*/
|
||||
```
|
||||
|
||||
=== "Java"
|
||||
|
||||
```java title=""
|
||||
/* Header comments for labeling functions, classes, test samples, etc */
|
||||
|
||||
// Comments for explaining details.
|
||||
|
||||
/**
|
||||
* Multiline
|
||||
* comments
|
||||
*/
|
||||
```
|
||||
|
||||
=== "C#"
|
||||
|
||||
```csharp title=""
|
||||
/* Header comments for labeling functions, classes, test samples, etc */
|
||||
|
||||
// Comments for explaining details.
|
||||
|
||||
/**
|
||||
* Multiline
|
||||
* comments
|
||||
*/
|
||||
```
|
||||
|
||||
=== "Go"
|
||||
|
||||
```go title=""
|
||||
/* Header comments for labeling functions, classes, test samples, etc */
|
||||
|
||||
// Comments for explaining details.
|
||||
|
||||
/**
|
||||
* Multiline
|
||||
* comments
|
||||
*/
|
||||
```
|
||||
|
||||
=== "Swift"
|
||||
|
||||
```swift title=""
|
||||
/* Header comments for labeling functions, classes, test samples, etc */
|
||||
|
||||
// Comments for explaining details.
|
||||
|
||||
/**
|
||||
* Multiline
|
||||
* comments
|
||||
*/
|
||||
```
|
||||
|
||||
=== "JS"
|
||||
|
||||
```javascript title=""
|
||||
/* Header comments for labeling functions, classes, test samples, etc */
|
||||
|
||||
// Comments for explaining details.
|
||||
|
||||
/**
|
||||
* Multiline
|
||||
* comments
|
||||
*/
|
||||
```
|
||||
|
||||
=== "TS"
|
||||
|
||||
```typescript title=""
|
||||
/* Header comments for labeling functions, classes, test samples, etc */
|
||||
|
||||
// Comments for explaining details.
|
||||
|
||||
/**
|
||||
* Multiline
|
||||
* comments
|
||||
*/
|
||||
```
|
||||
|
||||
=== "Dart"
|
||||
|
||||
```dart title=""
|
||||
/* Header comments for labeling functions, classes, test samples, etc */
|
||||
|
||||
// Comments for explaining details.
|
||||
|
||||
/**
|
||||
* Multiline
|
||||
* comments
|
||||
*/
|
||||
```
|
||||
|
||||
=== "Rust"
|
||||
|
||||
```rust title=""
|
||||
/* Header comments for labeling functions, classes, test samples, etc */
|
||||
|
||||
// Comments for explaining details.
|
||||
|
||||
/**
|
||||
* Multiline
|
||||
* comments
|
||||
*/
|
||||
```
|
||||
|
||||
=== "C"
|
||||
|
||||
```c title=""
|
||||
/* Header comments for labeling functions, classes, test samples, etc */
|
||||
|
||||
// Comments for explaining details.
|
||||
|
||||
/**
|
||||
* Multiline
|
||||
* comments
|
||||
*/
|
||||
```
|
||||
|
||||
=== "Kotlin"
|
||||
|
||||
```kotlin title=""
|
||||
/* Header comments for labeling functions, classes, test samples, etc */
|
||||
|
||||
// Comments for explaining details.
|
||||
|
||||
/**
|
||||
* Multiline
|
||||
* comments
|
||||
*/
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title=""
|
||||
// Header comments for labeling functions, classes, test samples, etc
|
||||
|
||||
// Comments for explaining details.
|
||||
|
||||
// Multiline
|
||||
// comments
|
||||
```
|
||||
|
||||
## Efficient Learning via Animated Illustrations
|
||||
|
||||
Compared with text, videos and pictures have a higher density of information and are more structured, making them easier to understand. In this book, **key and difficult concepts are mainly presented through animations and illustrations**, with text serving as explanations and supplements.
|
||||
|
||||
When encountering content with animations or illustrations as shown in the figure below, **prioritize understanding the figure, with text as supplementary**, integrating both for a comprehensive understanding.
|
||||
|
||||

|
||||
|
||||
## Deepen Understanding through Coding Practice
|
||||
|
||||
The source code of this book is hosted on the [GitHub Repository](https://github.com/krahets/hello-algo). As shown in the figure below, **the source code comes with test examples and can be executed with just a single click**.
|
||||
|
||||
If time permits, **it's recommended to type out the code yourself**. If pressed for time, at least read and run all the codes.
|
||||
|
||||
Compared to just reading code, writing code often yields more learning. **Learning by doing is the real way to learn.**
|
||||
|
||||

|
||||
|
||||
Setting up to run the code involves three main steps.
|
||||
|
||||
**Step 1: Install a local programming environment**. Follow the [tutorial](https://www.hello-algo.com/chapter_appendix/installation/) in the appendix for installation, or skip this step if already installed.
|
||||
|
||||
**Step 2: Clone or download the code repository**. Visit the [GitHub Repository](https://github.com/krahets/hello-algo).
|
||||
|
||||
If [Git](https://git-scm.com/downloads) is installed, use the following command to clone the repository:
|
||||
|
||||
```shell
|
||||
git clone https://github.com/krahets/hello-algo.git
|
||||
```
|
||||
|
||||
Alternatively, you can also click the "Download ZIP" button at the location shown in the figure below to directly download the code as a compressed ZIP file. Then, you can simply extract it locally.
|
||||
|
||||

|
||||
|
||||
**Step 3: Run the source code**. As shown in the figure below, for the code block labeled with the file name at the top, we can find the corresponding source code file in the `codes` folder of the repository. These files can be executed with a single click, which will help you save unnecessary debugging time and allow you to focus on learning.
|
||||
|
||||

|
||||
|
||||
## Learning Together in Discussion
|
||||
|
||||
While reading this book, please don't skip over the points that you didn't learn. **Feel free to post your questions in the comment section**. We will be happy to answer them and can usually respond within two days.
|
||||
|
||||
As illustrated in the figure below, each chapter features a comment section at the bottom. I encourage you to pay attention to these comments. They not only expose you to others' encountered problems, aiding in identifying knowledge gaps and sparking deeper contemplation, but also invite you to generously contribute by answering fellow readers' inquiries, sharing insights, and fostering mutual improvement.
|
||||
|
||||

|
||||
|
||||
## Algorithm Learning Path
|
||||
|
||||
Overall, the journey of mastering data structures and algorithms can be divided into three stages:
|
||||
|
||||
1. **Stage 1: Introduction to algorithms**. We need to familiarize ourselves with the characteristics and usage of various data structures and learn about the principles, processes, uses, and efficiency of different algorithms.
|
||||
2. **Stage 2: Practicing algorithm problems**. It is recommended to start from popular problems, such as [Sword for Offer](https://leetcode.cn/studyplan/coding-interviews/) and [LeetCode Hot 100](https://leetcode.cn/studyplan/top-100- liked/), and accumulate at least 100 questions to familiarize yourself with mainstream algorithmic problems. Forgetfulness can be a challenge when you start practicing, but rest assured that this is normal. We can follow the "Ebbinghaus Forgetting Curve" to review the questions, and usually after 3~5 rounds of repetitions, we will be able to memorize them.
|
||||
3. **Stage 3: Building the knowledge system**. In terms of learning, we can read algorithm column articles, solution frameworks, and algorithm textbooks to continuously enrich the knowledge system. In terms of practicing, we can try advanced strategies, such as categorizing by topic, multiple solutions for a single problem, and one solution for multiple problems, etc. Insights on these strategies can be found in various communities.
|
||||
|
||||
As shown in the figure below, this book mainly covers “Stage 1,” aiming to help you more efficiently embark on Stages 2 and 3.
|
||||
|
||||

|
||||
8
en/docs/chapter_preface/summary.md
Normal file
8
en/docs/chapter_preface/summary.md
Normal file
@ -0,0 +1,8 @@
|
||||
# Summary
|
||||
|
||||
- The main audience of this book is beginners in algorithm. If you already have some basic knowledge, this book can help you systematically review your algorithm knowledge, and the source code in this book can also be used as a "Coding Toolkit".
|
||||
- The book consists of three main sections, Complexity Analysis, Data Structures, and Algorithms, covering most of the topics in the field.
|
||||
- For newcomers to algorithms, it is crucial to read an introductory book in the beginning stages to avoid many detours or common pitfalls.
|
||||
- Animations and figures within the book are usually used to introduce key points and difficult knowledge. These should be given more attention when reading the book.
|
||||
- Practice is the best way to learn programming. It is highly recommended that you run the source code and type in the code yourself.
|
||||
- Each chapter in the web version of this book features a discussion section, and you are welcome to share your questions and insights at any time.
|
||||
Reference in New Issue
Block a user