translation: English Translation of the chapter of preface(part), introduction and complexity analysis(part) (#994)
* Translate 1.0.0b6 release with the machine learning translator. * Update Dockerfile A few translation improvements. * Fix a badge logo. * Fix EN translation of chapter_appendix/terminology.md (#913) * Update README.md * Update README.md * translation: Refined the automated translation of README (#932) * refined the automated translation of README * Update index.md * Update mkdocs-en.yml --------- Co-authored-by: Yudong Jin <krahets@163.com> * translate: Embellish chapter_computational_complexity/index.md (#940) * translation: Update chapter_computational_complexity/performance_evaluation.md (#943) * Update performance_evaluation.md * Update performance_evaluation.md * Update performance_evaluation.md change 'methods' to 'approaches' on line 15 * Update performance_evaluation.md on line 21, change the sentence to 'the results could be the opposite on another computer with different specifications.' * Update performance_evaluation.md delete two short sentence on line 5 and 6 * Update performance_evaluation.md change `unavoidable` to `inevitable` on line 48 * Update performance_evaluation.md small changes on line 23 * translation: Update terminology and improve readability in preface summary (#954) * Update terminology and improve readability in preface summary This commit made a few adjustments in the 'summary.md' file for clearer and more accessible language. "Brushing tool library" was replaced with "Coding Toolkit" to better reflect common terminology. Also, advice for beginners in algorithm learning journey was reformulated to imply a more positive approach avoiding detours and common pitfalls. The section related to the discussion forum was rewritten to sound more inviting to readers. * Format * Optimize the translation of chapter_introduction/algorithms_are_everywhere. * Add .gitignore to Java subfolder. * Update the button assets. * Fix the callout * translation: chapter_computational_complexity/summary to en (#953) * translate chapter_computational_complexity/summary * minor format * Update summary.md with comment * Update summary.md * Update summary.md * translation: chapter_introduction/what_is_dsa.md (#962) * Optimize translation of what_is_dsa.md * Update * translation: chapter_introduction/summary.md (#963) * Translate chapter_introduction/summary.md * Update * translation: Update README.md (#964) * Update en translation of README.md * Update README.md * translation: update space_complexity.md (#970) * update space_complexity.md * the rest of translation piece * Update space_complexity.md --------- Co-authored-by: ThomasQiu <thomas.qiu@mnfgroup.limited> Co-authored-by: Yudong Jin <krahets@163.com> * translation: Update chapter_introduction/index.md (#971) * Update index.md sorry, first time doing this... now this is the final change. changes: title of the chapter is shorter. refined the abstract. * Update index.md --------- Co-authored-by: Yudong Jin <krahets@163.com> * translation: Update chapter_data_structure/classification_of_data_structure.md (#980) * update classification_of_data_structure.md * Update classification_of_data_structure.md --------- Co-authored-by: Yudong Jin <krahets@163.com> * translation: Update chapter_introduction/algorithms_are_everywhere.md (#972) * Update algorithms_are_everywhere.md changed or refined parts of the words and sentences including tips. Some of them I didnt change that much because im worried that it might not meet the requirement of accuracy. some other ones i changed a lot to make it sound better, but also kind of following the same wording as the CN version * Update algorithms_are_everywhere.md re-edited the dictionary part from Piyin to just normal Eng dictionary. again thank you very much hpstory for you suggestion. * Update algorithms_are_everywhere.md --------- Co-authored-by: Yudong Jin <krahets@163.com> * Prepare merging into main branch. * Update buttons * Update Dockerfile * Update index.md * Update index.md * Update README * Fix index.md * Fix mkdocs-en.yml --------- Co-authored-by: Yuelin Xin <sc20yx2@leeds.ac.uk> Co-authored-by: Phoenix Xie <phoenixx0415@gmail.com> Co-authored-by: Sizhuo Long <longsizhuo@gmail.com> Co-authored-by: Spark <qizhang94@outlook.com> Co-authored-by: Thomas <thomasqiu7@gmail.com> Co-authored-by: ThomasQiu <thomas.qiu@mnfgroup.limited> Co-authored-by: K3v123 <123932560+K3v123@users.noreply.github.com> Co-authored-by: Jin <36914748+yanedie@users.noreply.github.com>
11
Dockerfile
|
@ -6,12 +6,15 @@ RUN pip install mkdocs-material==9.4.1 mkdocs-glightbox
|
||||||
|
|
||||||
WORKDIR /hello-algo
|
WORKDIR /hello-algo
|
||||||
|
|
||||||
COPY docs ./build/docs
|
|
||||||
COPY overrides ./build/overrides
|
COPY overrides ./build/overrides
|
||||||
|
COPY docs ./build/docs
|
||||||
|
COPY docs-en ./build/docs-en
|
||||||
COPY mkdocs.yml ./mkdocs.yml
|
COPY mkdocs.yml ./mkdocs.yml
|
||||||
|
COPY mkdocs-en.yml ./mkdocs-en.yml
|
||||||
|
|
||||||
RUN mkdocs build
|
RUN mkdocs build -f mkdocs.yml
|
||||||
|
RUN mkdocs build -f mkdocs-en.yml
|
||||||
|
|
||||||
|
WORKDIR /app/site
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
CMD ["python", "-m", "http.server", "8000"]
|
||||||
CMD ["mkdocs", "serve", "-a", "0.0.0.0:8000"]
|
|
||||||
|
|
87
README-en.md
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://www.hello-algo.com/en/">
|
||||||
|
<img src="https://www.hello-algo.com/en/index.assets/hello_algo_header.png" width="450">
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="https://readme-typing-svg.demolab.com?font=Noto+Sans+SC&weight=500&duration=3500&pause=2000&color=21C8B8¢er=true&vCenter=true&random=false&width=200&lines=Hello%2C+Algo+!" alt="hello-algo-typing-svg" />
|
||||||
|
</br>
|
||||||
|
Data Structures and Algorithms Crash Course with Animated Illustrations and Off-the-Shelf Code
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://www.hello-algo.com/en/">
|
||||||
|
<img src="https://www.hello-algo.com/en/index.assets/btn_read_online_dark.svg" width="120"></a>
|
||||||
|
<a href="https://github.com/krahets/hello-algo/releases">
|
||||||
|
<img src="https://www.hello-algo.com/en/index.assets/btn_download_pdf_dark.svg" width="120"></a>
|
||||||
|
<a href="https://github.com/krahets/hello-algo">
|
||||||
|
<img src="https://www.hello-algo.com/en/index.assets/btn_chinese_edition_dark.svg" width="120"></a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="https://www.hello-algo.com/en/index.assets/animation.gif" width="396">
|
||||||
|
<img src="https://www.hello-algo.com/en/index.assets/running_code.gif" width="396">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="https://img.shields.io/badge/Python-snow?logo=python&logoColor=3776AB">
|
||||||
|
<img src="https://img.shields.io/badge/C%2B%2B-snow?logo=c%2B%2B&logoColor=00599C">
|
||||||
|
<img src="https://img.shields.io/badge/Java-snow?logo=coffeescript&logoColor=FC4C02">
|
||||||
|
<img src="https://img.shields.io/badge/C%23-snow?logo=csharp&logoColor=512BD4">
|
||||||
|
<img src="https://img.shields.io/badge/Go-snow?logo=go&logoColor=00ADD8">
|
||||||
|
<img src="https://img.shields.io/badge/Swift-snow?logo=swift&logoColor=F05138">
|
||||||
|
<img src="https://img.shields.io/badge/JavaScript-snow?logo=javascript&logoColor=E9CE30">
|
||||||
|
<img src="https://img.shields.io/badge/TypeScript-snow?logo=typescript&logoColor=3178C6">
|
||||||
|
<img src="https://img.shields.io/badge/Dart-snow?logo=dart&logoColor=0175C2">
|
||||||
|
<img src="https://img.shields.io/badge/Rust-snow?logo=rust&logoColor=000000">
|
||||||
|
<img src="https://img.shields.io/badge/C-snow?logo=c&logoColor=A8B9CC">
|
||||||
|
<img src="https://img.shields.io/badge/Zig-snow?logo=zig&logoColor=F7A41D">
|
||||||
|
<img src="https://img.shields.io/badge/Stay%20Tuned-snow">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
> [!Important]
|
||||||
|
>
|
||||||
|
> We are working on Chinese-to-English translation. For more information please see [#914](https://github.com/krahets/hello-algo/issues/914).
|
||||||
|
|
||||||
|
## About
|
||||||
|
|
||||||
|
This open-source project aims to create a free and beginner-friendly crash course for data structures and algorithms.
|
||||||
|
|
||||||
|
- Animated illustrations, easy-to-understand content, and a smooth learning curve help beginners explore the "knowledge map" of data structures and algorithms.
|
||||||
|
- Run code with just one click, helping readers improve their programming skills and understand the working principle of algorithms and the underlying implementation of data structures.
|
||||||
|
- We encourage readers to help each other. Questions and comments are usually replied to within two days.
|
||||||
|
|
||||||
|
If you find this book helpful, please give it a Star :star: to support us, thank you!
|
||||||
|
|
||||||
|
## Endorsements
|
||||||
|
|
||||||
|
> "An easy-to-understand book on data structures and algorithms, which guides readers to learn by minds-on and hands-on. Strongly recommended for algorithm beginners!"
|
||||||
|
>
|
||||||
|
> **—— Junhui Deng, Professor of Computer Science, Tsinghua University**
|
||||||
|
|
||||||
|
> "If I had 'Hello Algo' when I was learning data structures and algorithms, it would have been 10 times easier!"
|
||||||
|
>
|
||||||
|
> **—— Mu Li, Senior Principal Scientist, Amazon**
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
This open-source book is continuously being updated, and we welcome your participation in this project to provide better learning content for readers.
|
||||||
|
|
||||||
|
- [Content Correction](https://www.hello-algo.com/en/chapter_appendix/contribution/): Please help us correct or point out mistakes in the comments section such as grammatical errors, missing content, ambiguities, invalid links, or code bugs.
|
||||||
|
- [Code Transpilation](https://github.com/krahets/hello-algo/issues/15): We look forward to your contributions in various programming languages. We currently support 12 languages including Python, Java, C++, Go, and JavaScript.
|
||||||
|
- [Chinese-to-English](https://github.com/krahets/hello-algo/tree/en): We would love to invite you to join our translation team. The members are mainly from computer-science-related fields, English majors, and native English speakers.
|
||||||
|
|
||||||
|
We welcome your valuable suggestions and feedback. If you have any questions, please submit Issues or reach out via WeChat: `krahets-jyd`.
|
||||||
|
|
||||||
|
We would like to dedicate our thanks to all the contributors of this book. It is their selfless dedication that has made this book better. They are:
|
||||||
|
|
||||||
|
<p align="left">
|
||||||
|
<a href="https://github.com/krahets/hello-algo/graphs/contributors">
|
||||||
|
<img width="550" src="https://contrib.rocks/image?repo=krahets/hello-algo" />
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
The texts, code, images, photos, and videos in this repository are licensed under [CC BY-NC-SA-4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/).
|
|
@ -14,6 +14,8 @@
|
||||||
<img src="https://www.hello-algo.com/index.assets/btn_read_online_dark.svg" width="155"></a>
|
<img src="https://www.hello-algo.com/index.assets/btn_read_online_dark.svg" width="155"></a>
|
||||||
<a href="https://github.com/krahets/hello-algo/releases">
|
<a href="https://github.com/krahets/hello-algo/releases">
|
||||||
<img src="https://www.hello-algo.com/index.assets/btn_download_pdf_dark.svg" width="155"></a>
|
<img src="https://www.hello-algo.com/index.assets/btn_download_pdf_dark.svg" width="155"></a>
|
||||||
|
<a href="https://github.com/krahets/hello-algo/blob/master/README-en.md">
|
||||||
|
<img src="https://www.hello-algo.com/index.assets/btn_english_edition_dark.svg" width="155"></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
|
|
2
codes/java/.gitignore
vendored
|
@ -1 +1 @@
|
||||||
build
|
build
|
||||||
|
|
BIN
docs-en/assets/covers/chapter_appendix.jpg
Normal file
After Width: | Height: | Size: 113 KiB |
BIN
docs-en/assets/covers/chapter_array_and_linkedlist.jpg
Normal file
After Width: | Height: | Size: 125 KiB |
BIN
docs-en/assets/covers/chapter_backtracking.jpg
Normal file
After Width: | Height: | Size: 126 KiB |
BIN
docs-en/assets/covers/chapter_complexity_analysis.jpg
Normal file
After Width: | Height: | Size: 94 KiB |
BIN
docs-en/assets/covers/chapter_data_structure.jpg
Normal file
After Width: | Height: | Size: 96 KiB |
BIN
docs-en/assets/covers/chapter_divide_and_conquer.jpg
Normal file
After Width: | Height: | Size: 116 KiB |
BIN
docs-en/assets/covers/chapter_dynamic_programming.jpg
Normal file
After Width: | Height: | Size: 164 KiB |
BIN
docs-en/assets/covers/chapter_graph.jpg
Normal file
After Width: | Height: | Size: 84 KiB |
BIN
docs-en/assets/covers/chapter_greedy.jpg
Normal file
After Width: | Height: | Size: 135 KiB |
BIN
docs-en/assets/covers/chapter_hashing.jpg
Normal file
After Width: | Height: | Size: 137 KiB |
BIN
docs-en/assets/covers/chapter_heap.jpg
Normal file
After Width: | Height: | Size: 109 KiB |
BIN
docs-en/assets/covers/chapter_introduction.jpg
Normal file
After Width: | Height: | Size: 136 KiB |
BIN
docs-en/assets/covers/chapter_preface.jpg
Normal file
After Width: | Height: | Size: 118 KiB |
BIN
docs-en/assets/covers/chapter_searching.jpg
Normal file
After Width: | Height: | Size: 128 KiB |
BIN
docs-en/assets/covers/chapter_sorting.jpg
Normal file
After Width: | Height: | Size: 60 KiB |
BIN
docs-en/assets/covers/chapter_stack_and_queue.jpg
Normal file
After Width: | Height: | Size: 103 KiB |
BIN
docs-en/assets/covers/chapter_tree.jpg
Normal file
After Width: | Height: | Size: 118 KiB |
13
docs-en/chapter_computational_complexity/index.md
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Complexity Analysis
|
||||||
|
|
||||||
|
<div class="center-table" markdown>
|
||||||
|
|
||||||
|
![complexity_analysis](../assets/covers/chapter_complexity_analysis.jpg)
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
!!! abstract
|
||||||
|
|
||||||
|
Complexity analysis is like a space-time guide in the vast universe of algorithms.
|
||||||
|
|
||||||
|
It leads us to explore deeply in the dimensions of time and space, in search of more elegant solutions.
|
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 28 KiB |
|
@ -0,0 +1,194 @@
|
||||||
|
# Iteration vs. Recursion
|
||||||
|
|
||||||
|
In data structures and algorithms, it is common to repeat a task, which is closely related to the complexity of the algorithm. There are two basic program structures that we usually use to repeat a task: iteration and recursion.
|
||||||
|
|
||||||
|
## Iteration
|
||||||
|
|
||||||
|
An "iteration iteration" is a control structure that repeats a task. In iteration, a program repeats the execution of a piece of code until the condition is no longer satisfied.
|
||||||
|
|
||||||
|
### For Loops
|
||||||
|
|
||||||
|
`for` loops are one of the most common forms of iteration, **suitable when the number of iterations is known in advance**.
|
||||||
|
|
||||||
|
The following function implements the summation $1 + 2 + \dots + n$ based on a `for` loop, and the result is recorded using the variable `res`. Note that `range(a, b)` in Python corresponds to a "left-closed-right-open" interval, which is traversed in the range $a, a + 1, \dots, b-1$.
|
||||||
|
|
||||||
|
```src
|
||||||
|
[file]{iteration}-[class]{}-[func]{for_loop}
|
||||||
|
```
|
||||||
|
|
||||||
|
The figure below shows the flow block diagram of this summation function.
|
||||||
|
|
||||||
|
![Flow block diagram of the summation function](iteration_and_recursion.assets/iteration.png)
|
||||||
|
|
||||||
|
The number of operations in this summation function is proportional to the size of the input data $n$, or a "linear relationship". In fact, **time complexity describes this "linear relationship"**. This is described in more detail in the next section.
|
||||||
|
|
||||||
|
### While Loop
|
||||||
|
|
||||||
|
Similar to a `for` loop, a `while` loop is a way to implement iteration. In a `while` loop, the program first checks the condition at each turn, and if the condition is true, it continues, otherwise it ends the loop.
|
||||||
|
|
||||||
|
Below, we use a `while` loop to realize the summation $1 + 2 + \dots + n$ .
|
||||||
|
|
||||||
|
```src
|
||||||
|
[file]{iteration}-[class]{}-[func]{while_loop}
|
||||||
|
```
|
||||||
|
|
||||||
|
In `while` loops, since the steps of initializing and updating condition variables are independent of the loop structure, **it has more degrees of freedom than `for` loops**.
|
||||||
|
|
||||||
|
For example, in the following code, the condition variable $i$ is updated twice per round, which is not convenient to implement with a `for` loop.
|
||||||
|
|
||||||
|
```src
|
||||||
|
[file]{iteration}-[class]{}-[func]{while_loop_ii}
|
||||||
|
```
|
||||||
|
|
||||||
|
Overall, **`for` loops have more compact code and `while` loops are more flexible**, and both can implement iteration structures. The choice of which one to use should be based on the needs of the particular problem.
|
||||||
|
|
||||||
|
### Nested Loops
|
||||||
|
|
||||||
|
We can nest one loop structure inside another, using the `for` loop as an example:
|
||||||
|
|
||||||
|
```src
|
||||||
|
[file]{iteration}-[class]{}-[func]{nested_for_loop}
|
||||||
|
```
|
||||||
|
|
||||||
|
The figure below gives the block diagram of the flow of this nested loop.
|
||||||
|
|
||||||
|
![Block diagram of the flow of nested loops](iteration_and_recursion.assets/nested_iteration.png)
|
||||||
|
|
||||||
|
In this case, the number of operations of the function is proportional to $n^2$, or the algorithm's running time is "squared" to the size of the input data $n$.
|
||||||
|
|
||||||
|
We can continue to add nested loops, and each nest is a "dimension up", which will increase the time complexity to "cubic relations", "quadratic relations", and so on.
|
||||||
|
|
||||||
|
## Recursion
|
||||||
|
|
||||||
|
"Recursion recursion is an algorithmic strategy to solve a problem by calling the function itself. It consists of two main phases.
|
||||||
|
|
||||||
|
1. **recursive**: the program calls itself deeper and deeper, usually passing smaller or simpler arguments, until a "termination condition" is reached.
|
||||||
|
2. **Recursion**: After the "termination condition" is triggered, the program returns from the deepest level of the recursion function, level by level, aggregating the results of each level.
|
||||||
|
|
||||||
|
And from an implementation point of view, recursion code contains three main elements.
|
||||||
|
|
||||||
|
1. **Termination condition**: used to decide when to switch from "recursive" to "inductive".
|
||||||
|
2. **Recursion call**: corresponds to "recursion", where the function calls itself, usually with smaller or more simplified input parameters.
|
||||||
|
3. **return result**: corresponds to "return", returning the result of the current recursion level to the previous one.
|
||||||
|
|
||||||
|
Observe the following code, we only need to call the function `recur(n)` , and the calculation of $1 + 2 + \dots + n$ is done:
|
||||||
|
|
||||||
|
```src
|
||||||
|
[file]{recursion}-[class]{}-[func]{recur}
|
||||||
|
```
|
||||||
|
|
||||||
|
The figure below shows the recursion of the function.
|
||||||
|
|
||||||
|
![Recursion process for the summation function](iteration_and_recursion.assets/recursion_sum.png)
|
||||||
|
|
||||||
|
Although iteration and recursion can yield the same results from a computational point of view, **they represent two completely different paradigms for thinking about and solving problems**.
|
||||||
|
|
||||||
|
- **Iteration**: solving problems "from the bottom up". Start with the most basic steps and repeat or add to them until the task is completed.
|
||||||
|
- **Recursion**: solving problems "from the top down". The original problem is broken down into smaller subproblems that have the same form as the original problem. Next, the subproblem continues to be broken down into smaller subproblems until it stops at the base case (the solution to the base case is known).
|
||||||
|
|
||||||
|
As an example of the above summation function, set the problem $f(n) = 1 + 2 + \dots + n$ .
|
||||||
|
|
||||||
|
- **Iteration**: the summation process is simulated in a loop, iterating from $1$ to $n$ and executing the summation operation in each round to find $f(n)$.
|
||||||
|
- **Recursion**: decompose the problem into subproblems $f(n) = n + f(n-1)$ and keep (recursively) decomposing until the base case $f(1) = 1$ terminates.
|
||||||
|
|
||||||
|
### Call The Stack
|
||||||
|
|
||||||
|
Each time a recursion function calls itself, the system allocates memory for the newly opened function to store local variables, call addresses, other information, and so on. This results in two things.
|
||||||
|
|
||||||
|
- The context data for a function is stored in an area of memory called "stack frame space" and is not freed until the function returns. As a result, **recursion is usually more memory-intensive than iteration**.
|
||||||
|
- Recursion calls to functions incur additional overhead. **Therefore recursion is usually less time efficient than loops**.
|
||||||
|
|
||||||
|
As shown in the figure below, before the termination condition is triggered, there are $n$ unreturned recursion functions at the same time, **with a recursion depth of $n$** .
|
||||||
|
|
||||||
|
![Recursion call depth](iteration_and_recursion.assets/recursion_sum_depth.png)
|
||||||
|
|
||||||
|
In practice, the depth of recursion allowed by a programming language is usually limited, and too deep a recursion may result in a stack overflow error.
|
||||||
|
|
||||||
|
### Tail Recursion
|
||||||
|
|
||||||
|
Interestingly, **if a function makes a recursion call only at the last step before returning**, the function can be optimized by the compiler or interpreter to be comparable to iteration in terms of space efficiency. This situation is called "tail recursion tail recursion".
|
||||||
|
|
||||||
|
- **Ordinary recursion**: when a function returns to a function at a higher level, it needs to continue executing the code, so the system needs to save the context of the previous call.
|
||||||
|
- **tail recursion**: the recursion call is the last operation before the function returns, which means that the function does not need to continue with other operations after returning to the previous level, so the system does not need to save the context of the previous function.
|
||||||
|
|
||||||
|
In the case of calculating $1 + 2 + \dots + n$, for example, we can implement tail recursion by setting the result variable `res` as a function parameter.
|
||||||
|
|
||||||
|
```src
|
||||||
|
[file]{recursion}-[class]{}-[func]{tail_recur}
|
||||||
|
```
|
||||||
|
|
||||||
|
The execution of tail recursion is shown in the figure below. Comparing normal recursion and tail recursion, the execution point of the summation operation is different.
|
||||||
|
|
||||||
|
- **Ordinary recursion**: the summing operation is performed during the "return" process, and the summing operation is performed again after returning from each level.
|
||||||
|
- **Tail recursion**: the summing operation is performed in a "recursion" process, the "recursion" process simply returns in levels.
|
||||||
|
|
||||||
|
![tail recursion process](iteration_and_recursion.assets/tail_recursion_sum.png)
|
||||||
|
|
||||||
|
!!! tip
|
||||||
|
|
||||||
|
Note that many compilers or interpreters do not support tail recursion optimization. For example, Python does not support tail recursion optimization by default, so even if a function is tail recursive, you may still encounter stack overflow problems.
|
||||||
|
|
||||||
|
### Recursion Tree
|
||||||
|
|
||||||
|
When dealing with algorithmic problems related to divide and conquer, recursion is often more intuitive and easier to read than iteration. Take the Fibonacci sequence as an example.
|
||||||
|
|
||||||
|
!!! question
|
||||||
|
|
||||||
|
Given a Fibonacci series $0, 1, 1, 2, 3, 5, 8, 13, \dots$ , find the $n$th number of the series.
|
||||||
|
|
||||||
|
Let the $n$th number of the Fibonacci series be $f(n)$ , which leads to two easy conclusions.
|
||||||
|
|
||||||
|
- The first two numbers of the series are $f(1) = 0$ and $f(2) = 1$.
|
||||||
|
- Each number in the series is the sum of the previous two numbers, i.e. $f(n) = f(n - 1) + f(n - 2)$ .
|
||||||
|
|
||||||
|
Recursion code can be written by making recursion calls according to the recursion relationship, using the first two numbers as termination conditions. Call `fib(n)` to get the $n$th number of the Fibonacci series.
|
||||||
|
|
||||||
|
```src
|
||||||
|
[file]{recursion}-[class]{}-[func]{fib}
|
||||||
|
```
|
||||||
|
|
||||||
|
Looking at the above code, we have recursively called two functions within a function, **this means that from one call, two call branches are created**. As shown in the figure below, this recursion will result in a recursion tree with the number of levels $n$.
|
||||||
|
|
||||||
|
![Recursion tree for Fibonacci series](iteration_and_recursion.assets/recursion_tree.png)
|
||||||
|
|
||||||
|
Essentially, recursion embodies the paradigm of "breaking down a problem into smaller sub-problems", and this divide and conquer strategy is essential.
|
||||||
|
|
||||||
|
- From an algorithmic point of view, many important algorithmic strategies such as searching, sorting algorithm, backtracking, divide and conquer, dynamic programming, etc. directly or indirectly apply this way of thinking.
|
||||||
|
- From a data structure point of view, recursion is naturally suited to problems related to linked lists, trees and graphs because they are well suited to be analyzed with the idea of partitioning.
|
||||||
|
|
||||||
|
## Compare The Two
|
||||||
|
|
||||||
|
To summarize the above, as shown in the table below, iteration and recursion differ in implementation, performance and applicability.
|
||||||
|
|
||||||
|
<p align="center"> Table <id> Comparison of iteration and recursion features </p>
|
||||||
|
|
||||||
|
| | iteration | recursion |
|
||||||
|
| ------------------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| implementation | circular structure | function call itself |
|
||||||
|
| time-efficient | typically efficient, no function call overhead | overhead on every function call |
|
||||||
|
| Memory Usage | Usually uses a fixed size of memory space | Cumulative function calls may use a lot of stack frame space |
|
||||||
|
| Applicable Problems | For simple cyclic tasks, code is intuitive and readable | For sub-problem decomposition, such as trees, graphs, divide and conquer, backtracking, etc., the code structure is concise and clear |
|
||||||
|
|
||||||
|
!!! tip
|
||||||
|
|
||||||
|
If you find the following solutions difficult to understand, you can review them after reading the "Stack" chapter.
|
||||||
|
|
||||||
|
So what is the intrinsic connection between iteration and recursion? In the case of the recursive function described above, the summing operation takes place in the "return" phase of the recursion. This means that the function that is initially called is actually the last to complete its summing operation, **This mechanism works in the same way as the stack's "first in, last out" principle**.
|
||||||
|
|
||||||
|
In fact, recursion terms like "call stack" and "stack frame space" already imply a close relationship between recursion and the stack.
|
||||||
|
|
||||||
|
1. **Recursive**: When a function is called, the system allocates a new stack frame on the "call stack" for the function, which is used to store the function's local variables, parameters, return address, and other data.
|
||||||
|
2. **Return to**: When a function completes execution and returns, the corresponding stack frame is removed from the "call stack", restoring the function's previous execution environment.
|
||||||
|
|
||||||
|
Thus, **we can use an explicit stack to model the behavior of the call stack**, thus transforming recursion into an iteration form:
|
||||||
|
|
||||||
|
```src
|
||||||
|
[file]{recursion}-[class]{}-[func]{for_loop_recur}
|
||||||
|
```
|
||||||
|
|
||||||
|
Observing the code above, it becomes more complex when recursion is converted to iteration. Although iteration and recursion can be converted to each other in many cases, it is not always worth doing so for two reasons.
|
||||||
|
|
||||||
|
- The transformed code may be more difficult to understand and less readable.
|
||||||
|
- For some complex problems, simulating the behavior of the system call stack can be very difficult.
|
||||||
|
|
||||||
|
In short, **the choice of iteration or recursion depends on the nature of the particular problem**. In programming practice, it is crucial to weigh the advantages and disadvantages of both and choose the appropriate method based on the context.
|
|
@ -0,0 +1,49 @@
|
||||||
|
# Evaluation Of Algorithm Efficiency
|
||||||
|
|
||||||
|
In algorithm design, we aim to achieve two goals in succession:
|
||||||
|
|
||||||
|
1. **Finding a Solution to the Problem**: The algorithm needs to reliably find the correct solution within the specified input range.
|
||||||
|
2. **Seeking the Optimal Solution**: There may be multiple ways to solve the same problem, and our goal is to find the most efficient algorithm possible.
|
||||||
|
|
||||||
|
In other words, once the ability to solve the problem is established, the efficiency of the algorithm emerges as the main benchmark for assessing its quality, which includes the following two aspects.
|
||||||
|
|
||||||
|
- **Time Efficiency**: The speed at which an algorithm runs.
|
||||||
|
- **Space Efficiency**: The amount of memory space the algorithm consumes.
|
||||||
|
|
||||||
|
In short, our goal is to design data structures and algorithms that are both "fast and economical". Effectively evaluating algorithm efficiency is crucial, as it allows for the comparison of different algorithms and guides the design and optimization process.
|
||||||
|
|
||||||
|
There are mainly two approaches for assessing efficiency: practical testing and theoretical estimation.
|
||||||
|
|
||||||
|
## Practical Testing
|
||||||
|
|
||||||
|
Let's consider a scenario where we have two algorithms, `A` and `B`, both capable of solving the same problem. To compare their efficiency, the most direct method is to use a computer to run both algorithms while monitoring and recording their execution time and memory usage. This approach provides a realistic assessment of their performance, but it also has significant limitations.
|
||||||
|
|
||||||
|
On one hand, it's challenging to eliminate the interference of the test environment. Hardware configurations can significantly affect the performance of algorithms. For instance, on one computer, Algorithm `A` might run faster than Algorithm `B`, but the results could be the opposite on another computer with different specifications. This means we would need to conduct tests on a variety of machines and calculate an average efficiency, which is impractical.
|
||||||
|
|
||||||
|
Furthermore, conducting comprehensive tests is resource-intensive. The efficiency of algorithms can vary with different volumes of input data. For example, with smaller data sets, Algorithm A might run faster than Algorithm B; however, this could change with larger data sets. Therefore, to reach a convincing conclusion, it's necessary to test a range of data sizes, which requires excessive computational resources.
|
||||||
|
|
||||||
|
## Theoretical Estimation
|
||||||
|
|
||||||
|
Given the significant limitations of practical testing, we can consider assessing algorithm efficiency solely through calculations. This method of estimation is known as 'asymptotic complexity analysis,' often simply referred to as 'complexity analysis.
|
||||||
|
|
||||||
|
Complexity analysis illustrates the relationship between the time (and space) resources required by an algorithm and the size of its input data. **It describes the growing trend in the time and space required for the execution of an algorithm as the size of the input data increases**. This definition might sound a bit complex, so let's break it down into three key points for easier understanding.
|
||||||
|
|
||||||
|
- In complexity analysis, 'time and space' directly relate to 'time complexity' and 'space complexity,' respectively.
|
||||||
|
- The statement "as the size of the input data increases" highlights that complexity analysis examines the interplay between the size of the input data and the algorithm's efficiency.
|
||||||
|
- Lastly, the phrase "the growing trend in time and space required" emphasizes that the focus of complexity analysis is not on the specific values of running time or space occupied, but on the rate at which these requirements increase with larger input sizes.
|
||||||
|
|
||||||
|
**Complexity analysis overcomes the drawbacks of practical testing methods in two key ways:**.
|
||||||
|
|
||||||
|
- It is independent of the testing environment, meaning the analysis results are applicable across all operating platforms.
|
||||||
|
- It effectively demonstrates the efficiency of algorithms with varying data volumes, particularly highlighting performance in large-scale data scenarios.
|
||||||
|
|
||||||
|
!!! tip
|
||||||
|
|
||||||
|
If you're still finding the concept of complexity confusing, don't worry. We will cover it in more detail in the subsequent chapters.
|
||||||
|
|
||||||
|
Complexity analysis provides us with a 'ruler' for evaluating the efficiency of algorithms, enabling us to measure the time and space resources required to execute a given algorithm and to compare the efficiency of different algorithms.
|
||||||
|
|
||||||
|
Complexity is a mathematical concept that might seem abstract and somewhat challenging for beginners. From this perspective, introducing complexity analysis at the very beginning may not be the most suitable approach. However, when discussing the characteristics of a particular data structure or algorithm, analyzing its operational speed and space usage is often inevitable.
|
||||||
|
|
||||||
|
Therefore, it is recommended that before diving deeply into data structures and algorithms, **one should first gain a basic understanding of complexity analysis. This foundational knowledge will facilitate the complexity analysis of simple algorithms.**
|
||||||
|
|
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 19 KiB |
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 29 KiB |
After Width: | Height: | Size: 17 KiB |
780
docs-en/chapter_computational_complexity/space_complexity.md
Normal file
|
@ -0,0 +1,780 @@
|
||||||
|
# Space Complexity
|
||||||
|
|
||||||
|
The space complexity is used to measure the growth trend of memory consumption as the scale of data increases for an algorithm solution. This concept is analogous to time complexity by replacing "runtime" with "memory space".
|
||||||
|
|
||||||
|
## Algorithmic Correlation Space
|
||||||
|
|
||||||
|
The memory space used by algorithms during its execution include the following types.
|
||||||
|
|
||||||
|
- **Input Space**: Used to store the input data for the algorithm.
|
||||||
|
- **Temporary Space**: Used to store variables, objects, function contexts, and other data of the algorithm during runtime.
|
||||||
|
- **Output Space**: Used to store the output data of the algorithm.
|
||||||
|
|
||||||
|
In general, the "Input Space" is excluded from the statistics of space complexity.
|
||||||
|
|
||||||
|
The **Temporary Space** can be further divided into three parts.
|
||||||
|
|
||||||
|
- **Temporary Data**: Used to store various constants, variables, objects, etc., during the the algorithm's execution.
|
||||||
|
- **Stack Frame Space**: Used to hold the context data of the called function. The system creates a stack frame at the top of the stack each time a function is called, and the stack frame space is freed when the function returns.
|
||||||
|
- **Instruction Space**: Used to hold compiled program instructions, usually ignored in practical statistics.
|
||||||
|
|
||||||
|
When analyzing the space complexity of a piece of program, **three parts are usually taken into account: Temporary Data, Stack Frame Space and Output Data**.
|
||||||
|
|
||||||
|
![Associated spaces used by the algorithm](space_complexity.assets/space_types.png)
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
|
||||||
|
```python title=""
|
||||||
|
class Node:
|
||||||
|
"""Classes""""
|
||||||
|
def __init__(self, x: int):
|
||||||
|
self.val: int = x # node value
|
||||||
|
self.next: Node | None = None # reference to the next node
|
||||||
|
|
||||||
|
def function() -> int:
|
||||||
|
""""Functions"""""
|
||||||
|
# Perform certain operations...
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def algorithm(n) -> int: # input data
|
||||||
|
A = 0 # temporary data (constant, usually in uppercase)
|
||||||
|
b = 0 # temporary data (variable)
|
||||||
|
node = Node(0) # temporary data (object)
|
||||||
|
c = function() # Stack frame space (call function)
|
||||||
|
return A + b + c # output data
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "C++"
|
||||||
|
|
||||||
|
```cpp title=""
|
||||||
|
/* Structures */
|
||||||
|
struct Node {
|
||||||
|
int val;
|
||||||
|
Node *next;
|
||||||
|
Node(int x) : val(x), next(nullptr) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Functions */
|
||||||
|
int func() {
|
||||||
|
// Perform certain operations...
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int algorithm(int n) { // input data
|
||||||
|
const int a = 0; // temporary data (constant)
|
||||||
|
int b = 0; // temporary data (variable)
|
||||||
|
Node* node = new Node(0); // temporary data (object)
|
||||||
|
int c = func(); // stack frame space (call function)
|
||||||
|
return a + b + c; // output data
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Java"
|
||||||
|
|
||||||
|
```java title=""
|
||||||
|
/* Classes */
|
||||||
|
class Node {
|
||||||
|
int val;
|
||||||
|
Node next;
|
||||||
|
Node(int x) { val = x; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Functions */
|
||||||
|
int function() {
|
||||||
|
// Perform certain operations...
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int algorithm(int n) { // input data
|
||||||
|
final int a = 0; // temporary data (constant)
|
||||||
|
int b = 0; // temporary data (variable)
|
||||||
|
Node node = new Node(0); // temporary data (object)
|
||||||
|
int c = function(); // stack frame space (call function)
|
||||||
|
return a + b + c; // output data
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "C#"
|
||||||
|
|
||||||
|
```csharp title=""
|
||||||
|
/* Classes */
|
||||||
|
class Node {
|
||||||
|
int val;
|
||||||
|
Node next;
|
||||||
|
Node(int x) { val = x; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Functions */
|
||||||
|
int Function() {
|
||||||
|
// Perform certain operations...
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Algorithm(int n) { // input data
|
||||||
|
const int a = 0; // temporary data (constant)
|
||||||
|
int b = 0; // temporary data (variable)
|
||||||
|
Node node = new(0); // temporary data (object)
|
||||||
|
int c = Function(); // stack frame space (call function)
|
||||||
|
return a + b + c; // output data
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Go"
|
||||||
|
|
||||||
|
```go title=""
|
||||||
|
/* Structures */
|
||||||
|
type node struct {
|
||||||
|
val int
|
||||||
|
next *node
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create node structure */
|
||||||
|
func newNode(val int) *node {
|
||||||
|
return &node{val: val}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Functions */
|
||||||
|
func function() int {
|
||||||
|
// Perform certain operations...
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func algorithm(n int) int { // input data
|
||||||
|
const a = 0 // temporary data (constant)
|
||||||
|
b := 0 // temporary storage of data (variable)
|
||||||
|
newNode(0) // temporary data (object)
|
||||||
|
c := function() // stack frame space (call function)
|
||||||
|
return a + b + c // output data
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Swift"
|
||||||
|
|
||||||
|
```swift title=""
|
||||||
|
/* Classes */
|
||||||
|
class Node {
|
||||||
|
var val: Int
|
||||||
|
var next: Node?
|
||||||
|
|
||||||
|
init(x: Int) {
|
||||||
|
val = x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Functions */
|
||||||
|
func function() -> Int {
|
||||||
|
// Perform certain operations...
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func algorithm(n: Int) -> Int { // input data
|
||||||
|
let a = 0 // temporary data (constant)
|
||||||
|
var b = 0 // temporary data (variable)
|
||||||
|
let node = Node(x: 0) // temporary data (object)
|
||||||
|
let c = function() // stack frame space (call function)
|
||||||
|
return a + b + c // output data
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "JS"
|
||||||
|
|
||||||
|
```javascript title=""
|
||||||
|
/* Classes */
|
||||||
|
class Node {
|
||||||
|
val;
|
||||||
|
next;
|
||||||
|
constructor(val) {
|
||||||
|
this.val = val === undefined ? 0 : val; // node value
|
||||||
|
this.next = null; // reference to the next node
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Functions */
|
||||||
|
function constFunc() {
|
||||||
|
// Perform certain operations
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function algorithm(n) { // input data
|
||||||
|
const a = 0; // temporary data (constant)
|
||||||
|
let b = 0; // temporary data (variable)
|
||||||
|
const node = new Node(0); // temporary data (object)
|
||||||
|
const c = constFunc(); // Stack frame space (calling function)
|
||||||
|
return a + b + c; // output data
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "TS"
|
||||||
|
|
||||||
|
```typescript title=""
|
||||||
|
/* Classes */
|
||||||
|
class Node {
|
||||||
|
val: number;
|
||||||
|
next: Node | null;
|
||||||
|
constructor(val?: number) {
|
||||||
|
this.val = val === undefined ? 0 : val; // node value
|
||||||
|
this.next = null; // reference to the next node
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Functions */
|
||||||
|
function constFunc(): number {
|
||||||
|
// Perform certain operations
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function algorithm(n: number): number { // input data
|
||||||
|
const a = 0; // temporary data (constant)
|
||||||
|
let b = 0; // temporary data (variable)
|
||||||
|
const node = new Node(0); // temporary data (object)
|
||||||
|
const c = constFunc(); // Stack frame space (calling function)
|
||||||
|
return a + b + c; // output data
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Dart"
|
||||||
|
|
||||||
|
```dart title=""
|
||||||
|
/* Classes */
|
||||||
|
class Node {
|
||||||
|
int val;
|
||||||
|
Node next;
|
||||||
|
Node(this.val, [this.next]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Functions */
|
||||||
|
int function() {
|
||||||
|
// Perform certain operations...
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int algorithm(int n) { // input data
|
||||||
|
const int a = 0; // temporary data (constant)
|
||||||
|
int b = 0; // temporary data (variable)
|
||||||
|
Node node = Node(0); // temporary data (object)
|
||||||
|
int c = function(); // stack frame space (call function)
|
||||||
|
return a + b + c; // output data
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Rust"
|
||||||
|
|
||||||
|
```rust title=""
|
||||||
|
use std::rc::Rc;
|
||||||
|
use std::cell::RefCell;
|
||||||
|
|
||||||
|
/* Structures */
|
||||||
|
struct Node {
|
||||||
|
val: i32,
|
||||||
|
next: Option<Rc<RefCell<Node>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Creating a Node structure */
|
||||||
|
impl Node {
|
||||||
|
fn new(val: i32) -> Self {
|
||||||
|
Self { val: val, next: None }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Functions */
|
||||||
|
fn function() -> i32 {
|
||||||
|
// Perform certain operations...
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn algorithm(n: i32) -> i32 { // input data
|
||||||
|
const a: i32 = 0; // temporary data (constant)
|
||||||
|
let mut b = 0; // temporary data (variable)
|
||||||
|
let node = Node::new(0); // temporary data (object)
|
||||||
|
let c = function(); // stack frame space (call function)
|
||||||
|
return a + b + c; // output data
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "C"
|
||||||
|
|
||||||
|
```c title=""
|
||||||
|
/* Functions */
|
||||||
|
int func() {
|
||||||
|
// Perform certain operations...
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int algorithm(int n) { // input data
|
||||||
|
const int a = 0; // temporary data (constant)
|
||||||
|
int b = 0; // temporary data (variable)
|
||||||
|
int c = func(); // stack frame space (call function)
|
||||||
|
return a + b + c; // output data
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Zig"
|
||||||
|
|
||||||
|
```zig title=""
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Calculation Method
|
||||||
|
|
||||||
|
The calculation method for space complexity is pretty similar to time complexity, with the only difference being that the focus shifts from "operation count" to "space usage size".
|
||||||
|
|
||||||
|
On top of that, unlike time complexity, **we usually only focus on the worst-case space complexity**. This is because memory space is a hard requirement, and we have to make sure that there is enough memory space reserved for all possibilities incurred by input data.
|
||||||
|
|
||||||
|
Looking at the following code, the "worst" in worst-case space complexity has two layers of meaning.
|
||||||
|
|
||||||
|
1. **Based on the worst-case input data**: when $n < 10$, the space complexity is $O(1)$; however, when $n > 10$, the initialized array `nums` occupies $O(n)$ space; thus the worst-case space complexity is $O(n)$.
|
||||||
|
2. **Based on the peak memory during algorithm execution**: for example, the program occupies $O(1)$ space until the last line is executed; when the array `nums` is initialized, the program occupies $O(n)$ space; thus the worst-case space complexity is $O(n)$.
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
|
||||||
|
```python title=""
|
||||||
|
def algorithm(n: int):
|
||||||
|
a = 0 # O(1)
|
||||||
|
b = [0] * 10000 # O(1)
|
||||||
|
if n > 10:
|
||||||
|
nums = [0] * n # O(n)
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "C++"
|
||||||
|
|
||||||
|
```cpp title=""
|
||||||
|
void algorithm(int n) {
|
||||||
|
int a = 0; // O(1)
|
||||||
|
vector<int> b(10000); // O(1)
|
||||||
|
if (n > 10)
|
||||||
|
vector<int> nums(n); // O(n)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Java"
|
||||||
|
|
||||||
|
```java title=""
|
||||||
|
void algorithm(int n) {
|
||||||
|
int a = 0; // O(1)
|
||||||
|
int[] b = new int[10000]; // O(1)
|
||||||
|
if (n > 10)
|
||||||
|
int[] nums = new int[n]; // O(n)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "C#"
|
||||||
|
|
||||||
|
```csharp title=""
|
||||||
|
void Algorithm(int n) {
|
||||||
|
int a = 0; // O(1)
|
||||||
|
int[] b = new int[10000]; // O(1)
|
||||||
|
if (n > 10) {
|
||||||
|
int[] nums = new int[n]; // O(n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Go"
|
||||||
|
|
||||||
|
```go title=""
|
||||||
|
func algorithm(n int) {
|
||||||
|
a := 0 // O(1)
|
||||||
|
b := make([]int, 10000) // O(1)
|
||||||
|
var nums []int
|
||||||
|
if n > 10 {
|
||||||
|
nums := make([]int, n) // O(n)
|
||||||
|
}
|
||||||
|
fmt.Println(a, b, nums)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Swift"
|
||||||
|
|
||||||
|
```swift title=""
|
||||||
|
func algorithm(n: Int) {
|
||||||
|
let a = 0 // O(1)
|
||||||
|
let b = Array(repeating: 0, count: 10000) // O(1)
|
||||||
|
if n > 10 {
|
||||||
|
let nums = Array(repeating: 0, count: n) // O(n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "JS"
|
||||||
|
|
||||||
|
```javascript title=""
|
||||||
|
function algorithm(n) {
|
||||||
|
const a = 0; // O(1)
|
||||||
|
const b = new Array(10000); // O(1)
|
||||||
|
if (n > 10) {
|
||||||
|
const nums = new Array(n); // O(n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "TS"
|
||||||
|
|
||||||
|
```typescript title=""
|
||||||
|
function algorithm(n: number): void {
|
||||||
|
const a = 0; // O(1)
|
||||||
|
const b = new Array(10000); // O(1)
|
||||||
|
if (n > 10) {
|
||||||
|
const nums = new Array(n); // O(n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Dart"
|
||||||
|
|
||||||
|
```dart title=""
|
||||||
|
void algorithm(int n) {
|
||||||
|
int a = 0; // O(1)
|
||||||
|
List<int> b = List.filled(10000, 0); // O(1)
|
||||||
|
if (n > 10) {
|
||||||
|
List<int> nums = List.filled(n, 0); // O(n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Rust"
|
||||||
|
|
||||||
|
```rust title=""
|
||||||
|
fn algorithm(n: i32) {
|
||||||
|
let a = 0; // O(1)
|
||||||
|
let b = [0; 10000]; // O(1)
|
||||||
|
if n > 10 {
|
||||||
|
let nums = vec![0; n as usize]; // O(n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "C"
|
||||||
|
|
||||||
|
```c title=""
|
||||||
|
void algorithm(int n) {
|
||||||
|
int a = 0; // O(1)
|
||||||
|
int b[10000]; // O(1)
|
||||||
|
if (n > 10)
|
||||||
|
int nums[n] = {0}; // O(n)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Zig"
|
||||||
|
|
||||||
|
```zig title=""
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
**In recursion functions, it is important to take into count the measurement of stack frame space**. For example in the following code:
|
||||||
|
|
||||||
|
- The function `loop()` calls $n$ times `function()` in a loop, and each round of `function()` returns and frees stack frame space, so the space complexity is still $O(1)$.
|
||||||
|
- The recursion function `recur()` will have $n$ unreturned `recur()` during runtime, thus occupying $O(n)$ of stack frame space.
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
|
||||||
|
```python title=""
|
||||||
|
def function() -> int:
|
||||||
|
# Perform certain operations
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def loop(n: int):
|
||||||
|
"""Loop O(1)"""""
|
||||||
|
for _ in range(n):
|
||||||
|
function()
|
||||||
|
|
||||||
|
def recur(n: int) -> int:
|
||||||
|
"""Recursion O(n)"""""
|
||||||
|
if n == 1: return
|
||||||
|
return recur(n - 1)
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "C++"
|
||||||
|
|
||||||
|
```cpp title=""
|
||||||
|
int func() {
|
||||||
|
// Perform certain operations
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* Cycle O(1) */
|
||||||
|
void loop(int n) {
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
func();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Recursion O(n) */
|
||||||
|
void recur(int n) {
|
||||||
|
if (n == 1) return;
|
||||||
|
return recur(n - 1);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Java"
|
||||||
|
|
||||||
|
```java title=""
|
||||||
|
int function() {
|
||||||
|
// Perform certain operations
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* Cycle O(1) */
|
||||||
|
void loop(int n) {
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
function();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Recursion O(n) */
|
||||||
|
void recur(int n) {
|
||||||
|
if (n == 1) return;
|
||||||
|
return recur(n - 1);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "C#"
|
||||||
|
|
||||||
|
```csharp title=""
|
||||||
|
int Function() {
|
||||||
|
// Perform certain operations
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* Cycle O(1) */
|
||||||
|
void Loop(int n) {
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
Function();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Recursion O(n) */
|
||||||
|
int Recur(int n) {
|
||||||
|
if (n == 1) return 1;
|
||||||
|
return Recur(n - 1);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Go"
|
||||||
|
|
||||||
|
```go title=""
|
||||||
|
func function() int {
|
||||||
|
// Perform certain operations
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Cycle O(1) */
|
||||||
|
func loop(n int) {
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
function()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Recursion O(n) */
|
||||||
|
func recur(n int) {
|
||||||
|
if n == 1 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
recur(n - 1)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Swift"
|
||||||
|
|
||||||
|
```swift title=""
|
||||||
|
@discardableResult
|
||||||
|
func function() -> Int {
|
||||||
|
// Perform certain operations
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Cycle O(1) */
|
||||||
|
func loop(n: Int) {
|
||||||
|
for _ in 0 ..< n {
|
||||||
|
function()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Recursion O(n) */
|
||||||
|
func recur(n: Int) {
|
||||||
|
if n == 1 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
recur(n: n - 1)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "JS"
|
||||||
|
|
||||||
|
```javascript title=""
|
||||||
|
function constFunc() {
|
||||||
|
// Perform certain operations
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* Cycle O(1) */
|
||||||
|
function loop(n) {
|
||||||
|
for (let i = 0; i < n; i++) {
|
||||||
|
constFunc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Recursion O(n) */
|
||||||
|
function recur(n) {
|
||||||
|
if (n === 1) return;
|
||||||
|
return recur(n - 1);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "TS"
|
||||||
|
|
||||||
|
```typescript title=""
|
||||||
|
function constFunc(): number {
|
||||||
|
// Perform certain operations
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* Cycle O(1) */
|
||||||
|
function loop(n: number): void {
|
||||||
|
for (let i = 0; i < n; i++) {
|
||||||
|
constFunc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Recursion O(n) */
|
||||||
|
function recur(n: number): void {
|
||||||
|
if (n === 1) return;
|
||||||
|
return recur(n - 1);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Dart"
|
||||||
|
|
||||||
|
```dart title=""
|
||||||
|
int function() {
|
||||||
|
// Perform certain operations
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* Cycle O(1) */
|
||||||
|
void loop(int n) {
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
function();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Recursion O(n) */
|
||||||
|
void recur(int n) {
|
||||||
|
if (n == 1) return;
|
||||||
|
return recur(n - 1);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Rust"
|
||||||
|
|
||||||
|
```rust title=""
|
||||||
|
fn function() -> i32 {
|
||||||
|
// Perform certain operations
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* Cycle O(1) */
|
||||||
|
fn loop(n: i32) {
|
||||||
|
for i in 0..n {
|
||||||
|
function();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Recursion O(n) */
|
||||||
|
void recur(n: i32) {
|
||||||
|
if n == 1 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
recur(n - 1);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "C"
|
||||||
|
|
||||||
|
```c title=""
|
||||||
|
int func() {
|
||||||
|
// Perform certain operations
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* Cycle O(1) */
|
||||||
|
void loop(int n) {
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
func();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Recursion O(n) */
|
||||||
|
void recur(int n) {
|
||||||
|
if (n == 1) return;
|
||||||
|
return recur(n - 1);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Zig"
|
||||||
|
|
||||||
|
```zig title=""
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Common Types
|
||||||
|
|
||||||
|
Assuming the input data size is $n$, the figure illustrates common types of space complexity (ordered from low to high).
|
||||||
|
|
||||||
|
$$
|
||||||
|
\begin{aligned}
|
||||||
|
O(1) < O(\log n) < O(n) < O(n^2) < O(2^n) \newline
|
||||||
|
\text{constant order} < \text{logarithmic order} < \text{linear order} < \text{square order} < \text{exponential order}
|
||||||
|
\end{aligned}
|
||||||
|
$$
|
||||||
|
|
||||||
|
![Common space complexity types](space_complexity.assets/space_complexity_common_types.png)
|
||||||
|
|
||||||
|
### Constant Order $O(1)$
|
||||||
|
|
||||||
|
Constant order is common for constants, variables, and objects whose quantity is unrelated to the size of the input data $n$.
|
||||||
|
|
||||||
|
It is important to note that memory occupied by initializing a variable or calling a function in a loop is released once the next iteration begins. Therefore, there is no accumulation of occupied space and the space complexity remains $O(1)$ :
|
||||||
|
|
||||||
|
```src
|
||||||
|
[file]{space_complexity}-[class]{}-[func]{constant}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Linear Order $O(N)$
|
||||||
|
|
||||||
|
Linear order is commonly found in arrays, linked lists, stacks, queues, and similar structures where the number of elements is proportional to $n$:
|
||||||
|
|
||||||
|
```src
|
||||||
|
[file]{space_complexity}-[class]{}-[func]{linear}
|
||||||
|
```
|
||||||
|
|
||||||
|
As shown in the figure below, the depth of recursion for this function is $n$, which means that there are $n$ unreturned `linear_recur()` functions at the same time, using $O(n)$ size stack frame space:
|
||||||
|
|
||||||
|
```src
|
||||||
|
[file]{space_complexity}-[class]{}-[func]{linear_recur}
|
||||||
|
```
|
||||||
|
|
||||||
|
![Linear order space complexity generated by recursion function](space_complexity.assets/space_complexity_recursive_linear.png)
|
||||||
|
|
||||||
|
### Quadratic Order $O(N^2)$
|
||||||
|
|
||||||
|
Quadratic order is common in matrices and graphs, where the number of elements is in a square relationship with $n$:
|
||||||
|
|
||||||
|
```src
|
||||||
|
[file]{space_complexity}-[class]{}-[func]{quadratic}
|
||||||
|
```
|
||||||
|
|
||||||
|
As shown in the figure below, the recursion depth of this function is $n$, and an array is initialized in each recursion function with lengths $n$, $n-1$, $\dots$, $2$, $1$, and an average length of $n / 2$, thus occupying $O(n^2)$ space overall:
|
||||||
|
|
||||||
|
```src
|
||||||
|
[file]{space_complexity}-[class]{}-[func]{quadratic_recur}
|
||||||
|
```
|
||||||
|
|
||||||
|
![Square-order space complexity generated by the recursion function](space_complexity.assets/space_complexity_recursive_quadratic.png)
|
||||||
|
|
||||||
|
### Exponential Order $O(2^N)$
|
||||||
|
|
||||||
|
Exponential order is common in binary trees. Looking at the figure below, a "full binary tree" of degree $n$ has $2^n - 1$ nodes, occupying $O(2^n)$ space:
|
||||||
|
|
||||||
|
```src
|
||||||
|
[file]{space_complexity}-[class]{}-[func]{build_tree}
|
||||||
|
```
|
||||||
|
|
||||||
|
![Exponential order space complexity generated by a full binary tree](space_complexity.assets/space_complexity_exponential.png)
|
||||||
|
|
||||||
|
### Logarithmic Order $O(\Log N)$
|
||||||
|
|
||||||
|
Logarithmic order is commonly used in divide and conquer algorithms. For example, in a merge sort, given an array of length $n$ as the input, each round of recursion divides the array in half from its midpoint to form a recursion tree of height $\log n$, using $O(\log n)$ stack frame space.
|
||||||
|
|
||||||
|
Another example is to convert a number into a string. Given a positive integer $n$ with a digit count of $\log_{10} n + 1$, the corresponding string length is $\log_{10} n + 1$. Therefore, the space complexity is $O(\log_{10} n + 1) = O(\log n)$.
|
||||||
|
|
||||||
|
## Weighing Time And Space
|
||||||
|
|
||||||
|
Ideally, we would like to optimize both the time complexity and the space complexity of an algorithm. However, in reality, simultaneously optimizing time and space complexity is often challenging.
|
||||||
|
|
||||||
|
**Reducing time complexity usually comes at the expense of increasing space complexity, and vice versa**. The approach of sacrificing memory space to improve algorithm speed is known as "trading space for time", while the opposite is called "trading time for space".
|
||||||
|
|
||||||
|
The choice between these approaches depends on which aspect we prioritize. In most cases, time is more valuable than space, so "trading space for time" is usually the more common strategy. Of course, in situations with large data volumes, controlling space complexity is also crucial.
|
49
docs-en/chapter_computational_complexity/summary.md
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
# Summary
|
||||||
|
|
||||||
|
### Highlights
|
||||||
|
|
||||||
|
**Evaluation of Algorithm Efficiency**
|
||||||
|
|
||||||
|
- Time and space efficiency are the two leading evaluation indicators to measure an algorithm.
|
||||||
|
- We can evaluate the efficiency of an algorithm through real-world testing. Still, it isn't easy to eliminate the side effects from the testing environment, and it consumes a lot of computational resources.
|
||||||
|
- Complexity analysis overcomes the drawbacks of real-world testing. The analysis results can apply to all operating platforms and reveal the algorithm's efficiency under variant data scales.
|
||||||
|
|
||||||
|
**Time Complexity**
|
||||||
|
|
||||||
|
- Time complexity is used to measure the trend of algorithm running time as the data size grows., which can effectively evaluate the algorithm's efficiency. However, it may fail in some cases, such as when the input volume is small or the time complexities are similar, making it difficult to precisely compare the efficiency of algorithms.
|
||||||
|
- The worst time complexity is denoted by big $O$ notation, which corresponds to the asymptotic upper bound of the function, reflecting the growth rate in the number of operations $T(n)$ as $n$ tends to positive infinity.
|
||||||
|
- The estimation of time complexity involves two steps: first, counting the number of operations, and then determining the asymptotic upper bound.
|
||||||
|
- Common time complexities, from lowest to highest, are $O(1)$, $O(\log n)$, $O(n)$, $O(n \log n)$, $O(n^2)$, $O(2^n)$, and $O(n!)$.
|
||||||
|
- The time complexity of certain algorithms is not fixed and depends on the distribution of the input data. The time complexity can be categorized into worst-case, best-case, and average. The best-case time complexity is rarely used because the input data must meet strict conditions to achieve the best-case.
|
||||||
|
- The average time complexity reflects the efficiency of an algorithm with random data inputs, which is closest to the performance of algorithms in real-world scenarios. Calculating the average time complexity requires statistical analysis of input data and a synthesized mathematical expectation.
|
||||||
|
|
||||||
|
**Space Complexity**
|
||||||
|
|
||||||
|
- Space complexity serves a similar purpose to time complexity and is used to measure the trend of space occupied by an algorithm as the data volume increases.
|
||||||
|
- The memory space associated with the operation of an algorithm can be categorized into input space, temporary space, and output space. Normally, the input space is not considered when determining space complexity. The temporary space can be classified into instruction space, data space, and stack frame space, and the stack frame space usually only affects the space complexity for recursion functions.
|
||||||
|
- We mainly focus on the worst-case space complexity, which refers to the measurement of an algorithm's space usage when given the worst-case input data and during the worst-case execution scenario.
|
||||||
|
- Common space complexities are $O(1)$, $O(\log n)$, $O(n)$, $O(n^2)$ and $O(2^n)$ from lowest to highest.
|
||||||
|
|
||||||
|
### Q & A
|
||||||
|
|
||||||
|
!!! question "Is the space complexity of tail recursion $O(1)$?"
|
||||||
|
|
||||||
|
Theoretically, the space complexity of a tail recursion function can be optimized to $O(1)$. However, most programming languages (e.g., Java, Python, C++, Go, C#, etc.) do not support auto-optimization for tail recursion, so the space complexity is usually considered as $O(n)$.
|
||||||
|
|
||||||
|
!!! question "What is the difference between the terms function and method?"
|
||||||
|
|
||||||
|
A *function* can be executed independently, and all arguments are passed explicitly. A *method* is associated with an object and is implicitly passed to the object that calls it, allowing it to operate on the data contained within an instance of a class.
|
||||||
|
|
||||||
|
Let's illustrate with a few common programming languages.
|
||||||
|
|
||||||
|
- C is a procedural programming language without object-oriented concepts, so it has only functions. However, we can simulate object-oriented programming by creating structures (struct), and the functions associated with structures are equivalent to methods in other languages.
|
||||||
|
- Java and C# are object-oriented programming languages, and blocks of code (methods) are typically part of a class. Static methods behave like a function because it is bound to the class and cannot access specific instance variables.
|
||||||
|
- Both C++ and Python support both procedural programming (functions) and object-oriented programming (methods).
|
||||||
|
|
||||||
|
!!! question "Does the figure "Common Types of Space Complexity" reflect the absolute size of the occupied space?"
|
||||||
|
|
||||||
|
No, that figure shows the space complexity, which reflects the growth trend, not the absolute size of the space occupied.
|
||||||
|
|
||||||
|
For example, if you take $n = 8$ , the values of each curve do not align with the function because each curve contains a constant term used to compress the range of values to a visually comfortable range.
|
||||||
|
|
||||||
|
In practice, since we usually don't know each method's "constant term" complexity, it is generally impossible to choose the optimal solution for $n = 8$ based on complexity alone. But it's easier to choose for $n = 8^5$ as the growth trend is already dominant.
|
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 15 KiB |
1092
docs-en/chapter_computational_complexity/time_complexity.md
Normal file
After Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 66 KiB |
|
@ -0,0 +1,49 @@
|
||||||
|
# Classification Of Data Structures
|
||||||
|
|
||||||
|
Common data structures include arrays, linked lists, stacks, queues, hash tables, trees, heaps, and graphs. They can be divided into two categories: logical structure and physical structure.
|
||||||
|
|
||||||
|
## Logical Structures: Linear And Non-linear
|
||||||
|
|
||||||
|
**Logical structures reveal logical relationships between data elements**. In arrays and linked lists, data are arranged in sequential order, reflecting the linear relationship between data; while in trees, data are arranged hierarchically from the top down, showing the derived relationship between ancestors and descendants; and graphs are composed of nodes and edges, reflecting the complex network relationship.
|
||||||
|
|
||||||
|
As shown in the figure below, logical structures can further be divided into "linear data structure" and "non-linear data structure". Linear data structures are more intuitive, meaning that the data are arranged linearly in terms of logical relationships; non-linear data structures, on the other hand, are arranged non-linearly.
|
||||||
|
|
||||||
|
- **Linear data structures**: arrays, linked lists, stacks, queues, hash tables.
|
||||||
|
- **Nonlinear data structures**: trees, heaps, graphs, hash tables.
|
||||||
|
|
||||||
|
![Linear and nonlinear data structures](classification_of_data_structure.assets/classification_logic_structure.png)
|
||||||
|
|
||||||
|
Non-linear data structures can be further divided into tree and graph structures.
|
||||||
|
|
||||||
|
- **Linear structures**: arrays, linked lists, queues, stacks, hash tables, with one-to-one sequential relationship between elements.
|
||||||
|
- **Tree structure**: tree, heap, hash table, with one-to-many relationship between elements.
|
||||||
|
- **Graph**: graph with many-to-many relationship between elements.
|
||||||
|
|
||||||
|
## Physical Structure: Continuous vs. Dispersed
|
||||||
|
|
||||||
|
**When an algorithm is running, the data being processed is stored in memory**. The figure below shows a computer memory module where each black square represents a memory space. We can think of the memory as a giant Excel sheet in which each cell can store data of a certain size.
|
||||||
|
|
||||||
|
**The system accesses the data at the target location by means of a memory address**. As shown in the figure below, the computer assigns a unique identifier to each cell in the table according to specific rules, ensuring that each memory space has a unique memory address. With these addresses, the program can access the data in memory.
|
||||||
|
|
||||||
|
![memory_strip, memory_space, memory_address](classification_of_data_structure.assets/computer_memory_location.png)
|
||||||
|
|
||||||
|
!!! tip
|
||||||
|
|
||||||
|
It is worth noting that comparing memory to the Excel sheet is a simplified analogy. The actual memory working mechanism is more complicated, involving the concepts of address, space, memory management, cache mechanism, virtual and physical memory.
|
||||||
|
|
||||||
|
Memory is a shared resource for all programs, and when a block of memory is occupied by one program, it cannot be used by other programs at the same time. **Therefore, considering memory resources is crucial in designing data structures and algorithms**. For example, the algorithm's peak memory usage should not exceed the remaining free memory of the system; if there is a lack of contiguous memory blocks, then the data structure chosen must be able to be stored in non-contiguous memory blocks.
|
||||||
|
|
||||||
|
As shown in the figure below, **Physical structure reflects the way data is stored in computer memory and it can be divided into consecutive space storage (arrays) and distributed space storage (linked lists)**. The physical structure determines how data is accessed, updated, added, deleted, etc. Logical and physical structure complement each other in terms of time efficiency and space efficiency.
|
||||||
|
|
||||||
|
![continuous vs. decentralized spatial storage](classification_of_data_structure.assets/classification_phisical_structure.png)
|
||||||
|
|
||||||
|
**It is worth stating that all data structures are implemented based on arrays, linked lists, or a combination of the two**. For example, stacks and queues can be implemented using both arrays and linked lists; and implementations of hash tables may contain both arrays and linked lists.
|
||||||
|
|
||||||
|
- **Array-based structures**: stacks, queues, hash tables, trees, heaps, graphs, matrices, tensors (arrays of dimension $\geq 3$), and so on.
|
||||||
|
- **Linked list-based structures**: stacks, queues, hash tables, trees, heaps, graphs, etc.
|
||||||
|
|
||||||
|
Data structures based on arrays are also known as "static data structures", which means that such structures' length remains constant after initialization. In contrast, data structures based on linked lists are called "dynamic data structures", meaning that their length can be adjusted during program execution after initialization.
|
||||||
|
|
||||||
|
!!! tip
|
||||||
|
|
||||||
|
If you find it difficult to understand the physical structure, it is recommended that you read the next chapter, "Arrays and Linked Lists," before reviewing this section.
|
13
docs-en/chapter_data_structure/index.md
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Data Structure
|
||||||
|
|
||||||
|
<div class="center-table" markdown>
|
||||||
|
|
||||||
|
![data structure](../assets/covers/chapter_data_structure.jpg)
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
!!! abstract
|
||||||
|
|
||||||
|
Data structures are like a solid and varied framework.
|
||||||
|
|
||||||
|
It provides a blueprint for the orderly organization of data upon which algorithms can come alive.
|
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 60 KiB |
56
docs-en/chapter_introduction/algorithms_are_everywhere.md
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
# Algorithms Are Everywhere
|
||||||
|
|
||||||
|
When we hear the word "algorithm", we naturally think of mathematics. However, many algorithms do not involve complex mathematics but rely more on basic logic, which is ubiquitous in our daily lives.
|
||||||
|
|
||||||
|
Before we formally discuss algorithms, an interesting fact is worth sharing: **you have already learned many algorithms unconsciously and have become accustomed to applying them in your daily life**. Below, I will give a few specific examples to prove this point.
|
||||||
|
|
||||||
|
**Example 1: Looking Up a Dictionary**. In a standard dictionary, each word corresponds to a phonetic transcription and the dictionary is organized alphabetically based on these transcriptions. Let's say we're looking for a word that begins with the letter $r$. This is typically done in the following way:
|
||||||
|
|
||||||
|
1. Open the dictionary around its midpoint and note the first letter on that page, assuming it to be $m$.
|
||||||
|
2. Given the sequence of words following the initial letter $m$, estimate where words starting with the letter $r$ might be located within the alphabetical order.
|
||||||
|
3. Iterate steps `1.` and `2.` until you find the page where the word begins with the letter $r$.
|
||||||
|
|
||||||
|
=== "<1>"
|
||||||
|
![Dictionary search step](algorithms_are_everywhere.assets/binary_search_dictionary_step1.png)
|
||||||
|
|
||||||
|
=== "<2>"
|
||||||
|
![binary_search_dictionary_step2](algorithms_are_everywhere.assets/binary_search_dictionary_step2.png)
|
||||||
|
|
||||||
|
=== "<3>"
|
||||||
|
![binary_search_dictionary_step3](algorithms_are_everywhere.assets/binary_search_dictionary_step3.png)
|
||||||
|
|
||||||
|
=== "<4>"
|
||||||
|
![binary_search_dictionary_step4](algorithms_are_everywhere.assets/binary_search_dictionary_step4.png)
|
||||||
|
|
||||||
|
=== "<5>"
|
||||||
|
![binary_search_dictionary_step5](algorithms_are_everywhere.assets/binary_search_dictionary_step5.png)
|
||||||
|
|
||||||
|
The skill of looking up a dictionary, essential for elementary school students, is actually the renowned binary search algorithm. Through the lens of data structures, we can view the dictionary as a sorted "array"; while from an algorithmic perspective, the series of operations in looking up a dictionary can be seen as "binary search".
|
||||||
|
|
||||||
|
**Example 2: Organizing Playing Cards**. When playing cards, we need to arrange the cards in ascending order each game, as shown in the following process.
|
||||||
|
|
||||||
|
1. Divide the playing cards into "ordered" and "unordered" parts, assuming initially that the leftmost card is already ordered.
|
||||||
|
2. Take out a card from the unordered part and insert it into the correct position in the ordered part; once completed, the leftmost two cards will be in an ordered sequence.
|
||||||
|
3. Continue the loop described in step `2.`, each iteration involving insertion of one card from the unordered segment into the ordered portion, until all cards are appropriately ordered.
|
||||||
|
|
||||||
|
![Playing cards sorting process](algorithms_are_everywhere.assets/playing_cards_sorting.png)
|
||||||
|
|
||||||
|
The above method of organizing playing cards is essentially the "insertion sort" algorithm, which is very efficient for small datasets. Many programming languages' sorting library functions include insertion sort.
|
||||||
|
|
||||||
|
**Example 3: Making Change**. Suppose we buy goods worth $69$ yuan at a supermarket and give the cashier $100$ yuan, then the cashier needs to give us $31$ yuan in change. They would naturally complete the thought process as shown below.
|
||||||
|
|
||||||
|
1. The options are currencies smaller than $31$, including $1$, $5$, $10$, and $20$.
|
||||||
|
2. Take out the largest $20$ from the options, leaving $31 - 20 = 11$.
|
||||||
|
3. Take out the largest $10$ from the remaining options, leaving $11 - 10 = 1$.
|
||||||
|
4. Take out the largest $1$ from the remaining options, leaving $1 - 1 = 0$.
|
||||||
|
5. Complete the change-making, with the solution being $20 + 10 + 1 = 31$.
|
||||||
|
|
||||||
|
![Change making process](algorithms_are_everywhere.assets/greedy_change.png)
|
||||||
|
|
||||||
|
In the aforementioned steps, at each stage, we make the optimal choice (utilizing the highest denomination possible), ultimately deriving at a feasible change-making approach. From the perspective of data structures and algorithms, this approach is essentially a "greedy" algorithm.
|
||||||
|
|
||||||
|
From preparing a dish to traversing interstellar realms, virtually every problem-solving endeavor relies on algorithms. The emergence of computers enables us to store data structures in memory and write code to call CPUs and GPUs to execute algorithms. Consequently, we can transfer real-life predicaments to computers, efficiently addressing a myriad of complex issues.
|
||||||
|
|
||||||
|
!!! tip
|
||||||
|
|
||||||
|
If concepts such as data structures, algorithms, arrays, and binary search still seem somewhat obsecure, I encourage you to continue reading. This book will gently guide you into the realm of understanding data structures and algorithms.
|
13
docs-en/chapter_introduction/index.md
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Introduction to Algorithms
|
||||||
|
|
||||||
|
<div class="center-table" markdown>
|
||||||
|
|
||||||
|
![A first look at the algorithm](../assets/covers/chapter_introduction.jpg)
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
!!! abstract
|
||||||
|
|
||||||
|
A graceful maiden dances, intertwined with the data, her skirt swaying to the melody of algorithms.
|
||||||
|
|
||||||
|
She invites you to a dance, follow her steps, and enter the world of algorithms full of logic and beauty.
|
9
docs-en/chapter_introduction/summary.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# Summary
|
||||||
|
|
||||||
|
- Algorithms are ubiquitous in daily life and are not as inaccessible and complex as they might seem. In fact, we have already unconsciously learned many algorithms to solve various problems in life.
|
||||||
|
- The principle of looking up a word in a dictionary is consistent with the binary search algorithm. The binary search algorithm embodies the important algorithmic concept of divide and conquer.
|
||||||
|
- The process of organizing playing cards is very similar to the insertion sort algorithm. The insertion sort algorithm is suitable for sorting small datasets.
|
||||||
|
- The steps of making change in currency essentially follow the greedy algorithm, where each step involves making the best possible choice at the moment.
|
||||||
|
- An algorithm is a set of instructions or steps used to solve a specific problem within a finite amount of time, while a data structure is the way data is organized and stored in a computer.
|
||||||
|
- Data structures and algorithms are closely linked. Data structures are the foundation of algorithms, and algorithms are the stage to utilize the functions of data structures.
|
||||||
|
- We can liken data structures and algorithms to building blocks. The blocks represent data, the shape and connection method of the blocks represent data structures, and the steps of assembling the blocks correspond to algorithms.
|
After Width: | Height: | Size: 1.2 MiB |
After Width: | Height: | Size: 20 KiB |
53
docs-en/chapter_introduction/what_is_dsa.md
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
# What is an Algorithm
|
||||||
|
|
||||||
|
## Definition of an Algorithm
|
||||||
|
|
||||||
|
An "algorithm" is a set of instructions or steps to solve a specific problem within a finite amount of time. It has the following characteristics:
|
||||||
|
|
||||||
|
- The problem is clearly defined, including unambiguous definitions of input and output.
|
||||||
|
- The algorithm is feasible, meaning it can be completed within a finite number of steps, time, and memory space.
|
||||||
|
- Each step has a definitive meaning. The output is consistently the same under the same inputs and conditions.
|
||||||
|
|
||||||
|
## Definition of a Data Structure
|
||||||
|
|
||||||
|
A "data structure" is a way of organizing and storing data in a computer, with the following design goals:
|
||||||
|
|
||||||
|
- Minimize space occupancy to save computer memory.
|
||||||
|
- Make data operations as fast as possible, covering data access, addition, deletion, updating, etc.
|
||||||
|
- Provide concise data representation and logical information to enable efficient algorithm execution.
|
||||||
|
|
||||||
|
**Designing data structures is a balancing act, often requiring trade-offs**. If you want to improve in one aspect, you often need to compromise in another. Here are two examples:
|
||||||
|
|
||||||
|
- Compared to arrays, linked lists offer more convenience in data addition and deletion but sacrifice data access speed.
|
||||||
|
- Graphs, compared to linked lists, provide richer logical information but require more memory space.
|
||||||
|
|
||||||
|
## Relationship Between Data Structures and Algorithms
|
||||||
|
|
||||||
|
As shown in the diagram below, data structures and algorithms are highly related and closely integrated, specifically in the following three aspects:
|
||||||
|
|
||||||
|
- Data structures are the foundation of algorithms. They provide structured data storage and methods for manipulating data for algorithms.
|
||||||
|
- Algorithms are the stage where data structures come into play. The data structure alone only stores data information; it is through the application of algorithms that specific problems can be solved.
|
||||||
|
- Algorithms can often be implemented based on different data structures, but their execution efficiency can vary greatly. Choosing the right data structure is key.
|
||||||
|
|
||||||
|
![Relationship between data structures and algorithms](what_is_dsa.assets/relationship_between_data_structure_and_algorithm.png)
|
||||||
|
|
||||||
|
Data structures and algorithms can be likened to a set of building blocks, as illustrated in the figure below. A building block set includes numerous pieces, accompanied by detailed assembly instructions. Following these instructions step by step allows us to construct an intricate block model.
|
||||||
|
|
||||||
|
![Assembling blocks](what_is_dsa.assets/assembling_blocks.jpg)
|
||||||
|
|
||||||
|
The detailed correspondence between the two is shown in the table below.
|
||||||
|
|
||||||
|
<p align="center"> Table <id> Comparing Data Structures and Algorithms to Building Blocks </p>
|
||||||
|
|
||||||
|
| Data Structures and Algorithms | Building Blocks |
|
||||||
|
| ------------------------------ | --------------------------------------------------------------- |
|
||||||
|
| Input data | Unassembled blocks |
|
||||||
|
| Data structure | Organization of blocks, including shape, size, connections, etc |
|
||||||
|
| Algorithm | A series of steps to assemble the blocks into the desired shape |
|
||||||
|
| Output data | Completed Block model |
|
||||||
|
|
||||||
|
It's worth noting that data structures and algorithms are independent of programming languages. For this reason, this book is able to provide implementations in multiple programming languages.
|
||||||
|
|
||||||
|
!!! tip "Conventional Abbreviation"
|
||||||
|
|
||||||
|
In real-life discussions, we often refer to "Data Structures and Algorithms" simply as "Algorithms". For example, the well-known LeetCode algorithm problems actually test both data structure and algorithm knowledge.
|
After Width: | Height: | Size: 161 KiB |
45
docs-en/chapter_preface/about_the_book.md
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
# The Book
|
||||||
|
|
||||||
|
The aim of this project is to create an open source, free, novice-friendly introductory tutorial on data structures and algorithms.
|
||||||
|
|
||||||
|
- Animated graphs are used throughout the book to structure the knowledge of data structures and algorithms in a way that is clear and easy to understand with a smooth learning curve.
|
||||||
|
- The source code of the algorithms can be run with a single click, supporting Java, C++, Python, Go, JS, TS, C#, Swift, Rust, Dart, Zig and other languages.
|
||||||
|
- Readers are encouraged to help each other and make progress in the chapter discussion forums, and questions and comments can usually be answered within two days.
|
||||||
|
|
||||||
|
## Target Readers
|
||||||
|
|
||||||
|
If you are a beginner to algorithms, have never touched an algorithm before, or already have some experience brushing up on data structures and algorithms, and have a vague understanding of data structures and algorithms, repeatedly jumping sideways between what you can and can't do, then this book is just for you!
|
||||||
|
|
||||||
|
If you have already accumulated a certain amount of questions and are familiar with most of the question types, then this book can help you review and organize the algorithm knowledge system, and the repository source code can be used as a "brushing tool library" or "algorithm dictionary".
|
||||||
|
|
||||||
|
If you are an algorithm expert, we look forward to receiving your valuable suggestions or [participate in the creation together](https://www.hello-algo.com/chapter_appendix/contribution/).
|
||||||
|
|
||||||
|
!!! success "precondition"
|
||||||
|
|
||||||
|
You will need to have at least a basic knowledge of programming in any language and be able to read and write simple code.
|
||||||
|
|
||||||
|
## Content Structure
|
||||||
|
|
||||||
|
The main contents of the book are shown in the figure below.
|
||||||
|
|
||||||
|
- **Complexity Analysis**: dimensions and methods of evaluation of data structures and algorithms. Methods of deriving time complexity, space complexity, common types, examples, etc.
|
||||||
|
- **Data Structures**: basic data types, classification methods of data structures. Definition, advantages and disadvantages, common operations, common types, typical applications, implementation methods of data structures such as arrays, linked lists, stacks, queues, hash tables, trees, heaps, graphs, etc.
|
||||||
|
- **Algorithms**: definitions, advantages and disadvantages, efficiency, application scenarios, solution steps, sample topics of search, sorting algorithms, divide and conquer, backtracking algorithms, dynamic programming, greedy algorithms, and more.
|
||||||
|
|
||||||
|
![Hello Algo content structure](about_the_book.assets/hello_algo_mindmap.jpg)
|
||||||
|
|
||||||
|
## Acknowledgements
|
||||||
|
|
||||||
|
During the creation of this book, I received help from many people, including but not limited to:
|
||||||
|
|
||||||
|
- Thank you to my mentor at the company, Dr. Shih Lee, for encouraging me to "get moving" during one of our conversations, which strengthened my resolve to write this book.
|
||||||
|
- I would like to thank my girlfriend Bubbles for being the first reader of this book, and for making many valuable suggestions from the perspective of an algorithm whiz, making this book more suitable for newbies.
|
||||||
|
- Thanks to Tengbao, Qibao, and Feibao for coming up with a creative name for this book that evokes fond memories of writing the first line of code "Hello World!".
|
||||||
|
- Thanks to Sutong for designing the beautiful cover and logo for this book and patiently revising it many times under my OCD.
|
||||||
|
- Thanks to @squidfunk for writing layout suggestions and for developing the open source documentation theme [Material-for-MkDocs](https://github.com/squidfunk/mkdocs-material/tree/master).
|
||||||
|
|
||||||
|
During the writing process, I read many textbooks and articles on data structures and algorithms. These works provide excellent models for this book and ensure the accuracy and quality of its contents. I would like to thank all my teachers and predecessors for their outstanding contributions!
|
||||||
|
|
||||||
|
This book promotes a hands-on approach to learning, and in this respect is heavily inspired by ["Hands-On Learning for Depth"](https://github.com/d2l-ai/d2l-zh). I highly recommend this excellent book to all readers.
|
||||||
|
|
||||||
|
A heartfelt thank you to my parents, it is your constant support and encouragement that gives me the opportunity to do this fun-filled thing.
|
13
docs-en/chapter_preface/index.md
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Preface
|
||||||
|
|
||||||
|
<div class="center-table" markdown>
|
||||||
|
|
||||||
|
![Preface](../assets/covers/chapter_preface.jpg)
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
!!! abstract
|
||||||
|
|
||||||
|
Algorithms are like a beautiful symphony, with each line of code flowing like a rhythm.
|
||||||
|
|
||||||
|
May this book ring softly in your head, leaving a unique and profound melody.
|
BIN
docs-en/chapter_preface/suggestions.assets/code_md_to_repo.png
Normal file
After Width: | Height: | Size: 59 KiB |
BIN
docs-en/chapter_preface/suggestions.assets/download_code.png
Normal file
After Width: | Height: | Size: 72 KiB |
BIN
docs-en/chapter_preface/suggestions.assets/learning_route.png
Normal file
After Width: | Height: | Size: 27 KiB |
224
docs-en/chapter_preface/suggestions.md
Normal file
|
@ -0,0 +1,224 @@
|
||||||
|
# How To Read
|
||||||
|
|
||||||
|
!!! tip
|
||||||
|
|
||||||
|
For the best reading experience, it is recommended that you read through this section.
|
||||||
|
|
||||||
|
## Conventions Of Style
|
||||||
|
|
||||||
|
- Those labeled `*` after the title are optional chapters with relatively difficult content. If you have limited time, it is advisable to skip them.
|
||||||
|
- Proper nouns and words and phrases with specific meanings are marked with `"double quotes"` to avoid ambiguity.
|
||||||
|
- Important proper nouns and their English translations are marked with `" "` in parentheses, e.g. `"array array"` . It is recommended to memorize them for reading the literature.
|
||||||
|
- **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 "empty".
|
||||||
|
- This book partially abandons the specification of annotations in programming languages in exchange for a more compact layout of the content. There are three main types of annotations: title annotations, content annotations, and multi-line annotations.
|
||||||
|
|
||||||
|
=== "Python"
|
||||||
|
|
||||||
|
```python title=""
|
||||||
|
"""Header comments for labeling functions, classes, test samples, etc.""""
|
||||||
|
|
||||||
|
# Content comments for detailed code solutions
|
||||||
|
|
||||||
|
"""
|
||||||
|
multi-line
|
||||||
|
marginal notes
|
||||||
|
"""
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "C++"
|
||||||
|
|
||||||
|
```cpp title=""
|
||||||
|
/* Header comments for labeling functions, classes, test samples, etc. */
|
||||||
|
|
||||||
|
// Content comments for detailed code solutions.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* multi-line
|
||||||
|
* marginal notes
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Java"
|
||||||
|
|
||||||
|
```java title=""
|
||||||
|
/* Header comments for labeling functions, classes, test samples, etc. */
|
||||||
|
|
||||||
|
// Content comments for detailed code solutions.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* multi-line
|
||||||
|
* marginal notes
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "C#"
|
||||||
|
|
||||||
|
```csharp title=""
|
||||||
|
/* Header comments for labeling functions, classes, test samples, etc. */
|
||||||
|
|
||||||
|
// Content comments for detailed code solutions.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* multi-line
|
||||||
|
* marginal notes
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Go"
|
||||||
|
|
||||||
|
```go title=""
|
||||||
|
/* Header comments for labeling functions, classes, test samples, etc. */
|
||||||
|
|
||||||
|
// Content comments for detailed code solutions.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* multi-line
|
||||||
|
* marginal notes
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Swift"
|
||||||
|
|
||||||
|
```swift title=""
|
||||||
|
/* Header comments for labeling functions, classes, test samples, etc. */
|
||||||
|
|
||||||
|
// Content comments for detailed code solutions.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* multi-line
|
||||||
|
* marginal notes
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "JS"
|
||||||
|
|
||||||
|
```javascript title=""
|
||||||
|
/* Header comments for labeling functions, classes, test samples, etc. */
|
||||||
|
|
||||||
|
// Content comments for detailed code solutions.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* multi-line
|
||||||
|
* marginal notes
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "TS"
|
||||||
|
|
||||||
|
```typescript title=""
|
||||||
|
/* Header comments for labeling functions, classes, test samples, etc. */
|
||||||
|
|
||||||
|
// Content comments for detailed code solutions.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* multi-line
|
||||||
|
* marginal notes
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Dart"
|
||||||
|
|
||||||
|
```dart title=""
|
||||||
|
/* Header comments for labeling functions, classes, test samples, etc. */
|
||||||
|
|
||||||
|
// Content comments for detailed code solutions.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* multi-line
|
||||||
|
* marginal notes
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Rust"
|
||||||
|
|
||||||
|
```rust title=""
|
||||||
|
/* Header comments for labeling functions, classes, test samples, etc. */
|
||||||
|
|
||||||
|
// Content comments for detailed code solutions.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* multi-line
|
||||||
|
* marginal notes
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "C"
|
||||||
|
|
||||||
|
```c title=""
|
||||||
|
/* Header comments for labeling functions, classes, test samples, etc. */
|
||||||
|
|
||||||
|
// Content comments for detailed code solutions.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* multi-line
|
||||||
|
* marginal notes
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
=== "Zig"
|
||||||
|
|
||||||
|
```zig title=""
|
||||||
|
// Header comments for labeling functions, classes, test samples, etc.
|
||||||
|
|
||||||
|
// Content comments for detailed code solutions.
|
||||||
|
|
||||||
|
// Multi-line
|
||||||
|
// Annotation
|
||||||
|
```
|
||||||
|
|
||||||
|
## Learn Efficiently In Animated Graphic Solutions
|
||||||
|
|
||||||
|
Compared with text, videos and pictures have a higher degree of information density and structure and are easier to understand. In this book, **key and difficult knowledge will be presented mainly in the form of animations and graphs**, while the text serves as an explanation and supplement to the animations and graphs.
|
||||||
|
|
||||||
|
If, while reading the book, you find that a particular paragraph provides an animation or a graphic solution as shown below, **please use the figure as the primary source and the text as a supplement and synthesize the two to understand the content**.
|
||||||
|
|
||||||
|
![Example animation](../index.assets/animation.gif)
|
||||||
|
|
||||||
|
## Deeper Understanding In Code Practice
|
||||||
|
|
||||||
|
The companion code for this book is hosted in the [GitHub repository](https://github.com/krahets/hello-algo). As shown in the figure below, **the source code is accompanied by test samples that can be run with a single click**.
|
||||||
|
|
||||||
|
If time permits, **it is recommended that you refer to the code and knock it through on your own**. If you have limited time to study, please read through and run all the code at least once.
|
||||||
|
|
||||||
|
The process of writing code is often more rewarding than reading it. **Learning by doing is really learning**.
|
||||||
|
|
||||||
|
![Running code example](../index.assets/running_code.gif)
|
||||||
|
|
||||||
|
The preliminaries for running the code are divided into three main steps.
|
||||||
|
|
||||||
|
**Step 1: Install the local programming environment**. Please refer to [Appendix Tutorial](https://www.hello-algo.com/chapter_appendix/installation/) for installation, or skip this step if already installed.
|
||||||
|
|
||||||
|
**Step 2: Clone or download the code repository**. If [Git](https://git-scm.com/downloads) is already installed, you can clone this repository with the following command.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
git clone https://github.com/krahets/hello-algo.git
|
||||||
|
```
|
||||||
|
|
||||||
|
Of course, you can also in the location shown in the figure below, click "Download ZIP" directly download the code zip, and then in the local solution.
|
||||||
|
|
||||||
|
![Clone repository with download code](suggestions.assets/download_code.png)
|
||||||
|
|
||||||
|
**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. The source code files can be run with a single click, which will help you save unnecessary debugging time and allow you to focus on what you are learning.
|
||||||
|
|
||||||
|
![Code block with corresponding source file](suggestions.assets/code_md_to_repo.png)
|
||||||
|
|
||||||
|
## Growing Together In Questioning And Discussion
|
||||||
|
|
||||||
|
While reading this book, please don't skip over the points that you didn't learn. **Feel free to ask your questions in the comment section**. We will be happy to answer them and can usually respond within two days.
|
||||||
|
|
||||||
|
As you can see in the figure below, each post comes with a comment section at the bottom. I hope you'll pay more attention to the comments section. On the one hand, you can learn about the problems that people encounter, so as to check the gaps and stimulate deeper thinking. On the other hand, we expect you to generously answer other partners' questions, share your insights, and help others improve.
|
||||||
|
|
||||||
|
![Example of comment section](../index.assets/comment.gif)
|
||||||
|
|
||||||
|
## Algorithm Learning Route
|
||||||
|
|
||||||
|
From a general point of view, we can divide the process of learning data structures and algorithms into three stages.
|
||||||
|
|
||||||
|
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. **Brush up on algorithm questions**. It is recommended to start brushing from popular topics, such as [Sword to Offer](https://leetcode.cn/studyplan/coding-interviews/) and [LeetCode Hot 100](https://leetcode.cn/studyplan/top-100- liked/), first accumulate at least 100 questions to familiarize yourself with mainstream algorithmic problems. Forgetfulness can be a challenge when first brushing up, 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. **Build 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 brushing, we can try to adopt advanced brushing strategies, such as categorizing by topic, multiple solutions, multiple solutions, etc. Related brushing tips can be found in various communities.
|
||||||
|
|
||||||
|
As shown in the figure below, this book mainly covers "Phase 1" and is designed to help you start Phase 2 and 3 more efficiently.
|
||||||
|
|
||||||
|
![algorithm learning route](suggestions.assets/learning_route.png)
|
8
docs-en/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 graphs 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 forum, and you are welcome to share your questions and insights at any time.
|
BIN
docs-en/index.assets/animation.gif
Normal file
After Width: | Height: | Size: 135 KiB |
1
docs-en/index.assets/btn_chinese_edition.svg
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<svg width="358" height="142" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" overflow="hidden"><g transform="translate(-3437 -1242)"><g><path d="M3438 1313C3438 1276 3468 1246 3505 1246L3726 1246C3763 1246 3793 1276 3793 1313 3793 1350 3763 1380 3726 1380L3505 1380C3468 1380 3438 1350 3438 1313Z" fill="#55AEA6" fill-rule="evenodd" fill-opacity="1"/><text fill="#FFFFFF" fill-opacity="1" font-family="Noto Sans SC Medium,Noto Sans SC Medium_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="500" font-stretch="normal" font-size="46" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 3606.97 1329)">中文版</text><g><g><g><path d="M0 17.2C0 12.4566 3.85656 8.59999 8.59999 8.59999L34.4 8.59999 40.85 8.59999 43 8.59999 77.3999 8.59999C82.1434 8.59999 85.9999 12.4566 85.9999 17.2L85.9999 51.6C85.9999 56.3434 82.1434 60.2 77.3999 60.2L43 60.2 40.85 60.2 34.4 60.2 8.59999 60.2C3.85656 60.2 0 56.3434 0 51.6L0 17.2ZM43 17.2 43 51.6 77.3999 51.6 77.3999 17.2 43 17.2ZM23.959 23.6365C23.529 22.669 22.5615 22.0375 21.5 22.0375 20.4384 22.0375 19.4709 22.669 19.0409 23.6365L10.4409 42.9865C9.83624 44.3437 10.4544 45.9293 11.8116 46.534 13.1687 47.1387 14.7544 46.5206 15.3591 45.1634L16.555 42.4625 26.445 42.4625 27.6409 45.1634C28.2456 46.5206 29.8312 47.1253 31.1884 46.534 32.5456 45.9428 33.1503 44.3437 32.559 42.9865L23.959 23.6365ZM21.5 31.3362 24.0531 37.0875 18.9469 37.0875 21.5 31.3362ZM60.2 22.0375C61.6781 22.0375 62.8875 23.2469 62.8875 24.725L62.8875 25.2625 68.7999 25.2625 70.95 25.2625C72.4281 25.2625 73.6374 26.4719 73.6374 27.95 73.6374 29.4281 72.4281 30.6375 70.95 30.6375L70.6812 30.6375 70.4662 31.2422C69.2703 34.5209 67.4562 37.504 65.145 40.0303 65.2659 40.1109 65.3868 40.1781 65.5078 40.2453L68.0474 41.7637C69.324 42.5297 69.7271 44.1825 68.9746 45.4456 68.2221 46.7087 66.5559 47.1253 65.2928 46.3728L62.7531 44.8543C62.1484 44.4915 61.5706 44.1153 60.9928 43.7122 59.5684 44.72 58.05 45.5934 56.424 46.319L55.9403 46.534C54.5831 47.1387 52.9975 46.5206 52.3928 45.1634 51.7881 43.8062 52.4062 42.2206 53.7634 41.6159L54.2472 41.4009C55.1071 41.0112 55.9403 40.5812 56.7331 40.084L55.0937 38.4447C54.0456 37.3965 54.0456 35.69 55.0937 34.6418 56.1418 33.5937 57.8484 33.5937 58.8965 34.6418L60.8584 36.6037 60.9256 36.6709C62.5918 34.9106 63.949 32.8681 64.93 30.624L60.2 30.624 50.525 30.624C49.0468 30.624 47.8375 29.4147 47.8375 27.9365 47.8375 26.4584 49.0468 25.249 50.525 25.249L57.5125 25.249 57.5125 24.7115C57.5125 23.2334 58.7218 22.024 60.2 22.024Z" fill="#FFFFFF" fill-rule="nonzero" fill-opacity="1" transform="matrix(1 0 0 1.00291 3499 1278)"/></g></g></g></g></g></svg>
|
After Width: | Height: | Size: 2.7 KiB |
1
docs-en/index.assets/btn_chinese_edition_dark.svg
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<svg width="358" height="142" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" overflow="hidden"><g transform="translate(-2699 -1242)"><g><path d="M2702 1313C2702 1276 2732 1246 2769 1246L2989 1246C3026 1246 3056 1276 3056 1313 3056 1350 3026 1380 2989 1380L2769 1380C2732 1380 2702 1350 2702 1313Z" fill="#52BBB1" fill-rule="evenodd" fill-opacity="1"/><text fill="#3B3B3B" fill-opacity="1" font-family="Noto Sans SC Medium,Noto Sans SC Medium_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="500" font-stretch="normal" font-size="46" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 2870.4 1329)">中文版</text><g><g><g><path d="M0 17.2C0 12.4566 3.85656 8.59999 8.59999 8.59999L34.4 8.59999 40.85 8.59999 43 8.59999 77.3999 8.59999C82.1434 8.59999 85.9999 12.4566 85.9999 17.2L85.9999 51.6C85.9999 56.3434 82.1434 60.2 77.3999 60.2L43 60.2 40.85 60.2 34.4 60.2 8.59999 60.2C3.85656 60.2 0 56.3434 0 51.6L0 17.2ZM43 17.2 43 51.6 77.3999 51.6 77.3999 17.2 43 17.2ZM23.959 23.6365C23.529 22.669 22.5615 22.0375 21.5 22.0375 20.4384 22.0375 19.4709 22.669 19.0409 23.6365L10.4409 42.9865C9.83624 44.3437 10.4544 45.9293 11.8116 46.534 13.1687 47.1387 14.7544 46.5206 15.3591 45.1634L16.555 42.4625 26.445 42.4625 27.6409 45.1634C28.2456 46.5206 29.8312 47.1253 31.1884 46.534 32.5456 45.9428 33.1503 44.3437 32.559 42.9865L23.959 23.6365ZM21.5 31.3362 24.0531 37.0875 18.9469 37.0875 21.5 31.3362ZM60.2 22.0375C61.6781 22.0375 62.8875 23.2469 62.8875 24.725L62.8875 25.2625 68.7999 25.2625 70.95 25.2625C72.4281 25.2625 73.6374 26.4719 73.6374 27.95 73.6374 29.4281 72.4281 30.6375 70.95 30.6375L70.6812 30.6375 70.4662 31.2422C69.2703 34.5209 67.4562 37.504 65.145 40.0303 65.2659 40.1109 65.3868 40.1781 65.5078 40.2453L68.0474 41.7637C69.324 42.5297 69.7271 44.1825 68.9746 45.4456 68.2221 46.7087 66.5559 47.1253 65.2928 46.3728L62.7531 44.8543C62.1484 44.4915 61.5706 44.1153 60.9928 43.7122 59.5684 44.72 58.05 45.5934 56.424 46.319L55.9403 46.534C54.5831 47.1387 52.9975 46.5206 52.3928 45.1634 51.7881 43.8062 52.4062 42.2206 53.7634 41.6159L54.2472 41.4009C55.1071 41.0112 55.9403 40.5812 56.7331 40.084L55.0937 38.4447C54.0456 37.3965 54.0456 35.69 55.0937 34.6418 56.1418 33.5937 57.8484 33.5937 58.8965 34.6418L60.8584 36.6037 60.9256 36.6709C62.5918 34.9106 63.949 32.8681 64.93 30.624L60.2 30.624 50.525 30.624C49.0468 30.624 47.8375 29.4147 47.8375 27.9365 47.8375 26.4584 49.0468 25.249 50.525 25.249L57.5125 25.249 57.5125 24.7115C57.5125 23.2334 58.7218 22.024 60.2 22.024Z" fill="#3B3B3B" fill-rule="nonzero" fill-opacity="1" transform="matrix(1 0 0 1.00291 2762 1278)"/></g></g></g></g></g></svg>
|
After Width: | Height: | Size: 2.7 KiB |
1
docs-en/index.assets/btn_download_pdf.svg
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<svg width="358" height="138" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" overflow="hidden"><g transform="translate(-3437 -838)"><g><path d="M3438 907C3438 869.997 3468 840 3505 840L3726 840C3763 840 3793 869.997 3793 907 3793 944.004 3763 974.001 3726 974.001L3505 974.001C3468 974.001 3438 944.004 3438 907Z" fill="#55AEA6" fill-rule="evenodd" fill-opacity="1"/><text fill="#FFFFFF" fill-opacity="1" font-family="Noto Sans SC Medium,Noto Sans SC Medium_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="500" font-stretch="normal" font-size="48" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 3629.6 924)">PDF</text><g><g><g><path d="M3515 882.125C3515 877.644 3518.64 874 3523.12 874L3543.44 874 3543.44 890.25C3543.44 892.497 3545.25 894.313 3547.5 894.313L3563.75 894.313 3563.75 912.594 3537.34 912.594C3532.86 912.594 3529.22 916.237 3529.22 920.719L3529.22 939 3523.12 939C3518.64 939 3515 935.357 3515 930.875L3515 882.125ZM3563.75 890.25 3547.5 890.25 3547.5 874 3563.75 890.25ZM3537.34 918.688 3541.41 918.688C3545.33 918.688 3548.52 921.874 3548.52 925.797 3548.52 929.72 3545.33 932.906 3541.41 932.906L3539.38 932.906 3539.38 936.969C3539.38 938.086 3538.46 939 3537.34 939 3536.23 939 3535.31 938.086 3535.31 936.969L3535.31 930.875 3535.31 920.719C3535.31 919.602 3536.23 918.688 3537.34 918.688ZM3541.41 928.844C3543.09 928.844 3544.45 927.486 3544.45 925.797 3544.45 924.109 3543.09 922.75 3541.41 922.75L3539.38 922.75 3539.38 928.844 3541.41 928.844ZM3553.59 918.688 3557.66 918.688C3561.02 918.688 3563.75 921.417 3563.75 924.781L3563.75 932.906C3563.75 936.271 3561.02 939 3557.66 939L3553.59 939C3552.48 939 3551.56 938.086 3551.56 936.969L3551.56 920.719C3551.56 919.602 3552.48 918.688 3553.59 918.688ZM3557.66 934.938C3558.77 934.938 3559.69 934.024 3559.69 932.906L3559.69 924.781C3559.69 923.664 3558.77 922.75 3557.66 922.75L3555.62 922.75 3555.62 934.938 3557.66 934.938ZM3567.81 920.719C3567.81 919.602 3568.73 918.688 3569.84 918.688L3575.94 918.688C3577.05 918.688 3577.97 919.602 3577.97 920.719 3577.97 921.836 3577.05 922.75 3575.94 922.75L3571.88 922.75 3571.88 926.813 3575.94 926.813C3577.05 926.813 3577.97 927.727 3577.97 928.844 3577.97 929.961 3577.05 930.875 3575.94 930.875L3571.88 930.875 3571.88 936.969C3571.88 938.086 3570.96 939 3569.84 939 3568.73 939 3567.81 938.086 3567.81 936.969L3567.81 928.844 3567.81 920.719Z" fill="#FFFFFF" fill-rule="nonzero" fill-opacity="1"/></g></g></g></g></g></svg>
|
After Width: | Height: | Size: 2.6 KiB |
1
docs-en/index.assets/btn_download_pdf_dark.svg
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<svg width="358" height="138" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" overflow="hidden"><g transform="translate(-2699 -838)"><g><path d="M2702 907C2702 869.997 2732 840 2769 840L2989 840C3026 840 3056 869.997 3056 907 3056 944.003 3026 974 2989 974L2769 974C2732 974 2702 944.003 2702 907Z" fill="#52BBB1" fill-rule="evenodd" fill-opacity="1"/><text fill="#3B3B3B" fill-opacity="1" font-family="Noto Sans SC Medium,Noto Sans SC Medium_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="500" font-stretch="normal" font-size="48" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 2893.03 924)">PDF</text><g><g><g><path d="M2779 882.125C2779 877.644 2782.64 874 2787.12 874L2807.44 874 2807.44 890.25C2807.44 892.497 2809.25 894.313 2811.5 894.313L2827.75 894.313 2827.75 912.594 2801.34 912.594C2796.86 912.594 2793.22 916.237 2793.22 920.719L2793.22 939 2787.12 939C2782.64 939 2779 935.357 2779 930.875L2779 882.125ZM2827.75 890.25 2811.5 890.25 2811.5 874 2827.75 890.25ZM2801.34 918.688 2805.41 918.688C2809.33 918.688 2812.52 921.874 2812.52 925.797 2812.52 929.72 2809.33 932.906 2805.41 932.906L2803.37 932.906 2803.37 936.969C2803.37 938.086 2802.46 939 2801.34 939 2800.23 939 2799.31 938.086 2799.31 936.969L2799.31 930.875 2799.31 920.719C2799.31 919.602 2800.23 918.688 2801.34 918.688ZM2805.41 928.844C2807.09 928.844 2808.45 927.486 2808.45 925.797 2808.45 924.109 2807.09 922.75 2805.41 922.75L2803.37 922.75 2803.37 928.844 2805.41 928.844ZM2817.59 918.688 2821.66 918.688C2825.02 918.688 2827.75 921.417 2827.75 924.781L2827.75 932.906C2827.75 936.271 2825.02 939 2821.66 939L2817.59 939C2816.48 939 2815.56 938.086 2815.56 936.969L2815.56 920.719C2815.56 919.602 2816.48 918.688 2817.59 918.688ZM2821.66 934.938C2822.77 934.938 2823.69 934.024 2823.69 932.906L2823.69 924.781C2823.69 923.664 2822.77 922.75 2821.66 922.75L2819.62 922.75 2819.62 934.938 2821.66 934.938ZM2831.81 920.719C2831.81 919.602 2832.73 918.688 2833.84 918.688L2839.94 918.688C2841.05 918.688 2841.97 919.602 2841.97 920.719 2841.97 921.836 2841.05 922.75 2839.94 922.75L2835.87 922.75 2835.87 926.813 2839.94 926.813C2841.05 926.813 2841.97 927.727 2841.97 928.844 2841.97 929.961 2841.05 930.875 2839.94 930.875L2835.87 930.875 2835.87 936.969C2835.87 938.086 2834.96 939 2833.84 939 2832.73 939 2831.81 938.086 2831.81 936.969L2831.81 928.844 2831.81 920.719Z" fill="#3B3B3B" fill-rule="nonzero" fill-opacity="1"/></g></g></g></g></g></svg>
|
After Width: | Height: | Size: 2.5 KiB |
1
docs-en/index.assets/btn_read_online.svg
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<svg width="358" height="142" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" overflow="hidden"><defs><clipPath id="clip0"><rect x="3501" y="672" width="82" height="65"/></clipPath><clipPath id="clip1"><rect x="3501" y="672" width="82" height="65"/></clipPath><clipPath id="clip2"><rect x="3501" y="672" width="82" height="65"/></clipPath></defs><g transform="translate(-3437 -632)"><g><path d="M3438 704C3438 666.997 3468 637 3505 637L3726 637C3763 637 3793 666.997 3793 704 3793 741.003 3763 771 3726 771L3505 771C3468 771 3438 741.003 3438 704Z" fill="#55AEA6" fill-rule="evenodd" fill-opacity="1"/><text fill="#FFFFFF" fill-opacity="1" font-family="Noto Sans SC Medium,Noto Sans SC Medium_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="500" font-stretch="normal" font-size="48" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 3625.58 721)">Web</text><g clip-path="url(#clip0)"><g clip-path="url(#clip1)"><g clip-path="url(#clip2)"><path d="M16.25 0C11.7685 0 8.125 3.64355 8.125 8.125L8.125 36.5625 2.4375 36.5625C1.0918 36.5625 0 37.6543 0 39 0 44.3828 4.36719 48.75 9.75 48.75L40.625 48.75 40.625 36.5625 16.25 36.5625 16.25 8.125 56.875 8.125 56.875 12.1875 65 12.1875 65 8.125C65 3.64355 61.3564 0 56.875 0L16.25 0ZM65 16.25 50.7812 16.25C47.417 16.25 44.6875 18.9795 44.6875 22.3437L44.6875 58.9062C44.6875 62.2705 47.417 65 50.7812 65L75.1562 65C78.5205 65 81.25 62.2705 81.25 58.9062L81.25 32.5 69.0625 32.5C66.8154 32.5 65 30.6846 65 28.4375L65 16.25ZM69.0625 16.25 69.0625 28.4375 81.25 28.4375 69.0625 16.25Z" fill="#FFFFFF" fill-rule="nonzero" fill-opacity="1" transform="matrix(1.00923 0 0 1 3501 672)"/></g></g></g></g></g></svg>
|
After Width: | Height: | Size: 1.8 KiB |
1
docs-en/index.assets/btn_read_online_dark.svg
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<svg width="358" height="142" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" overflow="hidden"><defs><clipPath id="clip0"><rect x="2765" y="672" width="81" height="65"/></clipPath><clipPath id="clip1"><rect x="2765" y="672" width="81" height="65"/></clipPath><clipPath id="clip2"><rect x="2765" y="672" width="81" height="65"/></clipPath></defs><g transform="translate(-2699 -632)"><g><path d="M2702 704C2702 666.997 2732 637 2769 637L2989 637C3026 637 3056 666.997 3056 704 3056 741.003 3026 771 2989 771L2769 771C2732 771 2702 741.003 2702 704Z" fill="#52BBB1" fill-rule="evenodd" fill-opacity="1"/><text fill="#3B3B3B" fill-opacity="1" font-family="Noto Sans SC Medium,Noto Sans SC Medium_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="500" font-stretch="normal" font-size="48" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 2889.02 721)">Web</text><g clip-path="url(#clip0)"><g clip-path="url(#clip1)"><g clip-path="url(#clip2)"><path d="M16.2 0C11.7323 0 8.09998 3.63233 8.09998 8.09998L8.09998 36.4499 2.42999 36.4499C1.08843 36.4499 0 37.5383 0 38.8799 0 44.2461 4.35374 48.5999 9.71997 48.5999L40.4999 48.5999 40.4999 36.4499 16.2 36.4499 16.2 8.09998 56.6998 8.09998 56.6998 12.15 64.7998 12.15 64.7998 8.09998C64.7998 3.63233 61.1675 0 56.6998 0L16.2 0ZM64.7998 16.2 50.6249 16.2C47.271 16.2 44.5499 18.921 44.5499 22.2749L44.5499 58.7248C44.5499 62.0787 47.271 64.7998 50.6249 64.7998L74.9248 64.7998C78.2787 64.7998 80.9998 62.0787 80.9998 58.7248L80.9998 32.3999 68.8498 32.3999C66.6097 32.3999 64.7998 30.5901 64.7998 28.3499L64.7998 16.2ZM68.8498 16.2 68.8498 28.3499 80.9998 28.3499 68.8498 16.2Z" fill="#3B3B3B" fill-rule="nonzero" fill-opacity="1" transform="matrix(1 0 0 1.00309 2765 672)"/></g></g></g></g></g></svg>
|
After Width: | Height: | Size: 1.9 KiB |
BIN
docs-en/index.assets/comment.gif
Normal file
After Width: | Height: | Size: 103 KiB |
BIN
docs-en/index.assets/conceptual_rendering.png
Normal file
After Width: | Height: | Size: 82 KiB |
BIN
docs-en/index.assets/hello_algo_header.png
Normal file
After Width: | Height: | Size: 206 KiB |
BIN
docs-en/index.assets/hello_algo_mindmap_tp.png
Normal file
After Width: | Height: | Size: 28 KiB |
BIN
docs-en/index.assets/running_code.gif
Normal file
After Width: | Height: | Size: 127 KiB |
173
docs-en/index.md
Normal file
|
@ -0,0 +1,173 @@
|
||||||
|
---
|
||||||
|
comments: true
|
||||||
|
glightbox: false
|
||||||
|
hide:
|
||||||
|
- footer
|
||||||
|
- toc
|
||||||
|
- edit
|
||||||
|
---
|
||||||
|
|
||||||
|
<div class="header-img-div" style="max-width: 500px;">
|
||||||
|
<img src="index.assets/conceptual_rendering.png" style="width: 37%; height: auto;">
|
||||||
|
<img src="index.assets/hello_algo_mindmap_tp.png" style="width: 63%; height: auto;">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h2 align="center">Hello Algo</h2>
|
||||||
|
|
||||||
|
<p align="center">Data Structures and Algorithms Crash Course with Animated Illustrations and Off-the-Shelf Code</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://github.com/krahets/hello-algo">
|
||||||
|
<img alt="GitHub repo stars" src="https://img.shields.io/github/stars/krahets/hello-algo?style=social&link=https%3A%2F%2Fgithub.com%2Fkrahets%2Fhello-algo">
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="https://github.com/krahets/hello-algo/releases">
|
||||||
|
<img alt="GitHub all releases" src="https://img.shields.io/github/downloads/krahets/hello-algo/total?style=social&logo=gitbook&logoColor=black&label=Downloads">
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="https://github.com/krahets/hello-algo">
|
||||||
|
<img alt="GitHub contributors" src="https://img.shields.io/github/contributors-anon/krahets/hello-algo?style=social&logo=git&logoColor=%23101010">
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://www.hello-algo.com/en/chapter_preface/" class="rounded-button">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="16" width="18" viewBox="0 0 576 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d="M249.6 471.5c10.8 3.8 22.4-4.1 22.4-15.5V78.6c0-4.2-1.6-8.4-5-11C247.4 52 202.4 32 144 32C93.5 32 46.3 45.3 18.1 56.1C6.8 60.5 0 71.7 0 83.8V454.1c0 11.9 12.8 20.2 24.1 16.5C55.6 460.1 105.5 448 144 448c33.9 0 79 14 105.6 23.5zm76.8 0C353 462 398.1 448 432 448c38.5 0 88.4 12.1 119.9 22.6c11.3 3.8 24.1-4.6 24.1-16.5V83.8c0-12.1-6.8-23.3-18.1-27.6C529.7 45.3 482.5 32 432 32c-58.4 0-103.4 20-123 35.6c-3.3 2.6-5 6.8-5 11V456c0 11.4 11.7 19.3 22.4 15.5z"/></svg>
|
||||||
|
Dive In
|
||||||
|
</a>
|
||||||
|
<a href="https://github.com/krahets/hello-algo" class="rounded-button">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="16px" width="15.5px" viewBox="0 0 496 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3 .3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5 .3-6.2 2.3zm44.2-1.7c-2.9 .7-4.9 2.6-4.6 4.9 .3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3 .7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3 .3 2.9 2.3 3.9 1.6 1 3.6 .7 4.3-.7 .7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3 .7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3 .7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/></svg>
|
||||||
|
Clone Repo
|
||||||
|
</a>
|
||||||
|
<a href="https://github.com/krahets/hello-algo/releases" class="rounded-button">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 512 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path d="M0 64C0 28.7 28.7 0 64 0L224 0l0 128c0 17.7 14.3 32 32 32l128 0 0 144-208 0c-35.3 0-64 28.7-64 64l0 144-48 0c-35.3 0-64-28.7-64-64L0 64zm384 64l-128 0L256 0 384 128zM176 352l32 0c30.9 0 56 25.1 56 56s-25.1 56-56 56l-16 0 0 32c0 8.8-7.2 16-16 16s-16-7.2-16-16l0-48 0-80c0-8.8 7.2-16 16-16zm32 80c13.3 0 24-10.7 24-24s-10.7-24-24-24l-16 0 0 48 16 0zm96-80l32 0c26.5 0 48 21.5 48 48l0 64c0 26.5-21.5 48-48 48l-32 0c-8.8 0-16-7.2-16-16l0-128c0-8.8 7.2-16 16-16zm32 128c8.8 0 16-7.2 16-16l0-64c0-8.8-7.2-16-16-16l-16 0 0 96 16 0zm80-112c0-8.8 7.2-16 16-16l48 0c8.8 0 16 7.2 16 16s-7.2 16-16 16l-32 0 0 32 32 0c8.8 0 16 7.2 16 16s-7.2 16-16 16l-32 0 0 48c0 8.8-7.2 16-16 16s-16-7.2-16-16l0-64 0-64z"/></svg>
|
||||||
|
Get PDF
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="https://img.shields.io/badge/Python-snow?logo=python&logoColor=3776AB">
|
||||||
|
<img src="https://img.shields.io/badge/C%2B%2B-snow?logo=c%2B%2B&logoColor=00599C">
|
||||||
|
<img src="https://img.shields.io/badge/Java-snow?logo=coffeescript&logoColor=FC4C02">
|
||||||
|
<img src="https://img.shields.io/badge/C%23-snow?logo=csharp&logoColor=512BD4">
|
||||||
|
<img src="https://img.shields.io/badge/Go-snow?logo=go&logoColor=00ADD8">
|
||||||
|
<img src="https://img.shields.io/badge/Swift-snow?logo=swift&logoColor=F05138">
|
||||||
|
<img src="https://img.shields.io/badge/JavaScript-snow?logo=javascript&logoColor=E9CE30">
|
||||||
|
<img src="https://img.shields.io/badge/TypeScript-snow?logo=typescript&logoColor=3178C6">
|
||||||
|
<img src="https://img.shields.io/badge/Dart-snow?logo=dart&logoColor=0175C2">
|
||||||
|
<img src="https://img.shields.io/badge/Rust-snow?logo=rust&logoColor=000000">
|
||||||
|
<img src="https://img.shields.io/badge/C-snow?logo=c&logoColor=A8B9CC">
|
||||||
|
<img src="https://img.shields.io/badge/Zig-snow?logo=zig&logoColor=F7A41D">
|
||||||
|
<img src="https://img.shields.io/badge/Stay%20Tuned-snow">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<h3 align="center">Endorsements</h3>
|
||||||
|
|
||||||
|
<div style="display: flex;">
|
||||||
|
<div class="admonition quote" style="flex: 1; margin-right: 0.4rem;">
|
||||||
|
<p class="admonition-title">Quote</p>
|
||||||
|
<p>"An easy-to-understand book on data structures and algorithms, which guides readers to learn by minds-on and hands-on. Strongly recommended for algorithm beginners!"</p>
|
||||||
|
<p><strong>—— Junhui Deng, Professor of Computer Science, Tsinghua University</strong></p>
|
||||||
|
</div>
|
||||||
|
<div class="admonition quote" style="flex: 1; margin-left: 0.4rem;">
|
||||||
|
<p class="admonition-title">Quote</p>
|
||||||
|
<p>"If I had 'Hello Algo' when I was learning data structures and algorithms, it would have been 10 times easier!"</p>
|
||||||
|
<p><strong>—— Mu Li, Senior Principal Scientist, Amazon</strong></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<div style="display: flex; align-items: center; margin: 2rem auto;">
|
||||||
|
<div style="flex: 1; margin: 0 2rem; display: flex; flex-direction: column; align-items: center;">
|
||||||
|
<div style="display: flex; flex-direction: column; align-items: center;">
|
||||||
|
<h3>Animated illustrations</h3>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="28" width="28" viewBox="0 0 640 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path fill="var(--md-primary-bg-color)" d="M256 0H576c35.3 0 64 28.7 64 64V288c0 35.3-28.7 64-64 64H256c-35.3 0-64-28.7-64-64V64c0-35.3 28.7-64 64-64zM476 106.7C471.5 100 464 96 456 96s-15.5 4-20 10.7l-56 84L362.7 169c-4.6-5.7-11.5-9-18.7-9s-14.2 3.3-18.7 9l-64 80c-5.8 7.2-6.9 17.1-2.9 25.4s12.4 13.6 21.6 13.6h80 48H552c8.9 0 17-4.9 21.2-12.7s3.7-17.3-1.2-24.6l-96-144zM336 96a32 32 0 1 0 -64 0 32 32 0 1 0 64 0zM64 128h96V384v32c0 17.7 14.3 32 32 32H320c17.7 0 32-14.3 32-32V384H512v64c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V192c0-35.3 28.7-64 64-64zm8 64c-8.8 0-16 7.2-16 16v16c0 8.8 7.2 16 16 16H88c8.8 0 16-7.2 16-16V208c0-8.8-7.2-16-16-16H72zm0 104c-8.8 0-16 7.2-16 16v16c0 8.8 7.2 16 16 16H88c8.8 0 16-7.2 16-16V312c0-8.8-7.2-16-16-16H72zm0 104c-8.8 0-16 7.2-16 16v16c0 8.8 7.2 16 16 16H88c8.8 0 16-7.2 16-16V416c0-8.8-7.2-16-16-16H72zm336 16v16c0 8.8 7.2 16 16 16h16c8.8 0 16-7.2 16-16V416c0-8.8-7.2-16-16-16H424c-8.8 0-16 7.2-16 16z"/></svg>
|
||||||
|
</div>
|
||||||
|
<p style="text-align: center;">Easy to understand</br>Smooth learning curve</p>
|
||||||
|
</div>
|
||||||
|
<img src="index.assets/animation.gif" class="cover-image" style="flex-shrink: 0; width: auto; max-width: 50%; border-radius: 0.5rem;">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="admonition quote">
|
||||||
|
<p align="center">"A picture is worth a thousand words."</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="display: flex; align-items: center; margin: 2rem auto;">
|
||||||
|
<img src="index.assets/running_code.gif" class="cover-image" style="flex-shrink: 0; width: auto; max-width: 50%; border-radius: 0.5rem;">
|
||||||
|
<div style="flex: 1; margin: 0 2rem; display: flex; flex-direction: column; align-items: center;">
|
||||||
|
<div style="display: flex; flex-direction: column; align-items: center;">
|
||||||
|
<h3>Off-the-Shelf Code</h3>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="28" width="28" viewBox="0 0 640 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path fill="var(--md-primary-bg-color)" d="M392.8 1.2c-17-4.9-34.7 5-39.6 22l-128 448c-4.9 17 5 34.7 22 39.6s34.7-5 39.6-22l128-448c4.9-17-5-34.7-22-39.6zm80.6 120.1c-12.5 12.5-12.5 32.8 0 45.3L562.7 256l-89.4 89.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l112-112c12.5-12.5 12.5-32.8 0-45.3l-112-112c-12.5-12.5-32.8-12.5-45.3 0zm-306.7 0c-12.5-12.5-32.8-12.5-45.3 0l-112 112c-12.5 12.5-12.5 32.8 0 45.3l112 112c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L77.3 256l89.4-89.4c12.5-12.5 12.5-32.8 0-45.3z"/></svg>
|
||||||
|
</div>
|
||||||
|
<p style="text-align: center;">Multi programming languages</br>Run with one click</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="admonition quote">
|
||||||
|
<p align="center">"Talk is cheap. Show me the code."</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="display: flex; align-items: center; margin: 2rem auto;">
|
||||||
|
<div style="flex: 1; margin: 0 2rem; display: flex; flex-direction: column; align-items: center;">
|
||||||
|
<div style="display: flex; flex-direction: column; align-items: center;">
|
||||||
|
<h3>Learning Together</h3>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="28" width="28" viewBox="0 0 640 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2023 Fonticons, Inc.--><path fill="var(--md-primary-bg-color)" d="M88.2 309.1c9.8-18.3 6.8-40.8-7.5-55.8C59.4 230.9 48 204 48 176c0-63.5 63.8-128 160-128s160 64.5 160 128s-63.8 128-160 128c-13.1 0-25.8-1.3-37.8-3.6c-10.4-2-21.2-.6-30.7 4.2c-4.1 2.1-8.3 4.1-12.6 6c-16 7.2-32.9 13.5-49.9 18c2.8-4.6 5.4-9.1 7.9-13.6c1.1-1.9 2.2-3.9 3.2-5.9zM0 176c0 41.8 17.2 80.1 45.9 110.3c-.9 1.7-1.9 3.5-2.8 5.1c-10.3 18.4-22.3 36.5-36.6 52.1c-6.6 7-8.3 17.2-4.6 25.9C5.8 378.3 14.4 384 24 384c43 0 86.5-13.3 122.7-29.7c4.8-2.2 9.6-4.5 14.2-6.8c15.1 3 30.9 4.5 47.1 4.5c114.9 0 208-78.8 208-176S322.9 0 208 0S0 78.8 0 176zM432 480c16.2 0 31.9-1.6 47.1-4.5c4.6 2.3 9.4 4.6 14.2 6.8C529.5 498.7 573 512 616 512c9.6 0 18.2-5.7 22-14.5c3.8-8.8 2-19-4.6-25.9c-14.2-15.6-26.2-33.7-36.6-52.1c-.9-1.7-1.9-3.4-2.8-5.1C622.8 384.1 640 345.8 640 304c0-94.4-87.9-171.5-198.2-175.8c4.1 15.2 6.2 31.2 6.2 47.8l0 .6c87.2 6.7 144 67.5 144 127.4c0 28-11.4 54.9-32.7 77.2c-14.3 15-17.3 37.6-7.5 55.8c1.1 2 2.2 4 3.2 5.9c2.5 4.5 5.2 9 7.9 13.6c-17-4.5-33.9-10.7-49.9-18c-4.3-1.9-8.5-3.9-12.6-6c-9.5-4.8-20.3-6.2-30.7-4.2c-12.1 2.4-24.7 3.6-37.8 3.6c-61.7 0-110-26.5-136.8-62.3c-16 5.4-32.8 9.4-50 11.8C279 439.8 350 480 432 480z"/></svg>
|
||||||
|
</div>
|
||||||
|
<p style="text-align: center;">Discussion and questions welcome</br>Readers progress together</p>
|
||||||
|
</div>
|
||||||
|
<img src="index.assets/comment.gif" class="cover-image" style="flex-shrink: 0; width: auto; max-width: 50%; border-radius: 0.5rem;">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="admonition quote">
|
||||||
|
<p align="center">"Chase the wind and moon, never stopping"</p>
|
||||||
|
<p align="center">"Beyond the plains, there are spring mountains"</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<h3 align="center"> Preface </h3>
|
||||||
|
|
||||||
|
Two years ago, I shared the "Sword Offer" series of problem solutions on LeetCode, which received much love and support from many students. During my interactions with readers, the most common question I encountered was "How to get started with algorithms." Gradually, I developed a deep interest in this question.
|
||||||
|
|
||||||
|
Blindly solving problems seems to be the most popular method, being simple, direct, and effective. However, problem-solving is like playing a "Minesweeper" game, where students with strong self-learning abilities can successfully clear the mines one by one, but those with insufficient foundations may end up bruised from explosions, retreating step by step in frustration. Thoroughly reading textbooks is also common, but for students aiming for job applications, the energy consumed by graduation, resume submissions, and preparing for written tests and interviews makes tackling thick books a daunting challenge.
|
||||||
|
|
||||||
|
If you are facing similar troubles, then you are lucky to have found this book. This book is my answer to this question, not necessarily the best solution, but at least an active attempt. Although this book won't directly land you an Offer, it will guide you through the "knowledge map" of data structures and algorithms, help you understand the shape, size, and distribution of different "mines," and equip you with various "demining methods." With these skills, I believe you can more comfortably solve problems and read literature, gradually building a complete knowledge system.
|
||||||
|
|
||||||
|
I deeply agree with Professor Feynman's saying: "Knowledge isn't free. You have to pay attention." In this sense, this book is not entirely "free." To not disappoint the precious "attention" you pay to this book, I will do my utmost, investing the greatest "attention" to complete the creation of this book.
|
||||||
|
|
||||||
|
<h3 align="left"> Author </h3>
|
||||||
|
|
||||||
|
Yudong Jin([Krahets](https://leetcode.cn/u/jyd/)), Senior Algorithm Engineer in a top tech company, Master's degree from Shanghai Jiao Tong University. The highest-read blogger across the entire LeetCode, his published ["Illustration of Algorithm Data Structures"](https://leetcode.cn/leetbook/detail/illustration-of-algorithm/) has been subscribed to by over 300k.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<h3 align="center"> Contribution </h3>
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://github.com/krahets/hello-algo/graphs/contributors">
|
||||||
|
<img width="550" src="https://contrib.rocks/image?repo=krahets/hello-algo">
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
The code review work for this book was completed by Gonglja, gvenusleo, hpstory, justin‐tse, krahets, night-cruise, nuomi1, Reanon, and sjinzh (listed in alphabetical order). Thanks to them for their time and effort, ensuring the standardization and uniformity of the code in various languages.
|
||||||
|
|
||||||
|
<div class="center-table">
|
||||||
|
<table style="border: none;">
|
||||||
|
<tbody>
|
||||||
|
<td align="center" style="border: none;"><a href="https://github.com/Gonglja"><img style="border-radius: 50%;" src="https://avatars.githubusercontent.com/u/39959756?v=4" width="50px;" alt="Gonglja"/></br><sub><b>Gonglja</b></sub></a></br><sub>C, C++</sub></td>
|
||||||
|
<td align="center" style="border: none;"><a href="https://github.com/gvenusleo"><img style="border-radius: 50%;" src="https://avatars.githubusercontent.com/u/79075347?v=4" width="50px;" alt="gvenusleo"/></br><sub><b>gvenusleo</b></sub></a></br><sub>Dart</sub></td>
|
||||||
|
<td align="center" style="border: none;"><a href="https://github.com/hpstory"><img style="border-radius: 50%;" src="https://avatars.githubusercontent.com/u/33348162?v=4" width="50px;" alt="hpstory"/></br><sub><b>hpstory</b></sub></a></br><sub>C#</sub></td>
|
||||||
|
<td align="center" style="border: none;"><a href="https://github.com/justin-tse"><img style="border-radius: 50%;" src="https://avatars.githubusercontent.com/u/24556310?v=4" width="50px;" alt="justin-tse"/></br><sub><b>justin-tse</b></sub></a></br><sub>JS, TS</sub></td>
|
||||||
|
<td align="center" style="border: none;"><a href="https://github.com/krahets"><img style="border-radius: 50%;" src="https://avatars.githubusercontent.com/u/26993056?v=4" width="50px;" alt="krahets"/></br><sub><b>krahets</b></sub></a></br><sub>Java, Python</sub></td>
|
||||||
|
<td align="center" style="border: none;"><a href="https://github.com/night-cruise"><img style="border-radius: 50%;" src="https://avatars.githubusercontent.com/u/77157236?v=4" width="50px;" alt="night-cruise"/></br><sub><b>night-cruise</b></sub></a></br><sub>Rust</sub></td>
|
||||||
|
<td align="center" style="border: none;"><a href="https://github.com/nuomi1"><img style="border-radius: 50%;" src="https://avatars.githubusercontent.com/u/3739017?v=4" width="50px;" alt="nuomi1"/></br><sub><b>nuomi1</b></sub></a></br><sub>Swift</sub></td>
|
||||||
|
<td align="center" style="border: none;"><a href="https://github.com/Reanon"><img style="border-radius: 50%;" src="https://avatars.githubusercontent.com/u/22005836?v=4" width="50px;" alt="Reanon"/></br><sub><b>Reanon</b></sub></a></br><sub>Go, C</sub></td>
|
||||||
|
<td align="center" style="border: none;"><a href="https://github.com/sjinzh"><img style="border-radius: 50%;" src="https://avatars.githubusercontent.com/u/99076655?v=4" width="50px;" alt="sjinzh"/></br><sub><b>sjinzh</b></sub></a></br><sub>Rust, Zig</sub></td>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
|
@ -1 +1 @@
|
||||||
<svg width="463" height="142" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" overflow="hidden"><g transform="translate(-2493 -1026)"><g><path d="M2497 1098C2497 1061 2527 1031 2564 1031L2885 1031C2922 1031 2952 1061 2952 1098L2952 1098C2952 1135 2922 1165 2885 1165L2564 1165C2527 1165 2497 1135 2497 1098Z" fill="#52BBB1" fill-rule="evenodd" fill-opacity="0.901961"/><text fill="#FFFFFF" fill-opacity="1" font-family="Noto Sans SC Medium,Noto Sans SC Medium_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="500" font-stretch="normal" font-size="48" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 2677.55 1115)">下载</text><text fill="#FFFFFF" fill-opacity="1" font-family="Noto Sans SC Medium,Noto Sans SC Medium_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="500" font-stretch="normal" font-size="48" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 2784.69 1115)">PDF</text><g><g><g><path d="M2577 1074.12C2577 1069.64 2580.64 1066 2585.12 1066L2605.44 1066 2605.44 1082.25C2605.44 1084.5 2607.25 1086.31 2609.5 1086.31L2625.75 1086.31 2625.75 1104.59 2599.34 1104.59C2594.86 1104.59 2591.22 1108.24 2591.22 1112.72L2591.22 1131 2585.12 1131C2580.64 1131 2577 1127.36 2577 1122.88L2577 1074.12ZM2625.75 1082.25 2609.5 1082.25 2609.5 1066 2625.75 1082.25ZM2599.34 1110.69 2603.41 1110.69C2607.33 1110.69 2610.52 1113.87 2610.52 1117.8 2610.52 1121.72 2607.33 1124.91 2603.41 1124.91L2601.38 1124.91 2601.38 1128.97C2601.38 1130.09 2600.46 1131 2599.34 1131 2598.23 1131 2597.31 1130.09 2597.31 1128.97L2597.31 1122.88 2597.31 1112.72C2597.31 1111.6 2598.23 1110.69 2599.34 1110.69ZM2603.41 1120.84C2605.09 1120.84 2606.45 1119.49 2606.45 1117.8 2606.45 1116.11 2605.09 1114.75 2603.41 1114.75L2601.38 1114.75 2601.38 1120.84 2603.41 1120.84ZM2615.59 1110.69 2619.66 1110.69C2623.02 1110.69 2625.75 1113.42 2625.75 1116.78L2625.75 1124.91C2625.75 1128.27 2623.02 1131 2619.66 1131L2615.59 1131C2614.48 1131 2613.56 1130.09 2613.56 1128.97L2613.56 1112.72C2613.56 1111.6 2614.48 1110.69 2615.59 1110.69ZM2619.66 1126.94C2620.77 1126.94 2621.69 1126.02 2621.69 1124.91L2621.69 1116.78C2621.69 1115.66 2620.77 1114.75 2619.66 1114.75L2617.62 1114.75 2617.62 1126.94 2619.66 1126.94ZM2629.81 1112.72C2629.81 1111.6 2630.73 1110.69 2631.84 1110.69L2637.94 1110.69C2639.05 1110.69 2639.97 1111.6 2639.97 1112.72 2639.97 1113.84 2639.05 1114.75 2637.94 1114.75L2633.88 1114.75 2633.88 1118.81 2637.94 1118.81C2639.05 1118.81 2639.97 1119.73 2639.97 1120.84 2639.97 1121.96 2639.05 1122.88 2637.94 1122.88L2633.88 1122.88 2633.88 1128.97C2633.88 1130.09 2632.96 1131 2631.84 1131 2630.73 1131 2629.81 1130.09 2629.81 1128.97L2629.81 1120.84 2629.81 1112.72Z" fill="#FFFFFF" fill-rule="nonzero" fill-opacity="1"/></g></g></g></g></g></svg>
|
<svg width="458" height="138" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" overflow="hidden"><g transform="translate(-1952 -838)"><g><path d="M1954 907C1954 869.997 1984 840 2021 840L2342 840C2379 840 2409 869.997 2409 907L2409 907C2409 944.003 2379 974 2342 974L2021 974C1984 974 1954 944.003 1954 907Z" fill="#55AEA6" fill-rule="evenodd" fill-opacity="1"/><text fill="#FFFFFF" fill-opacity="1" font-family="Noto Sans SC Medium,Noto Sans SC Medium_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="500" font-stretch="normal" font-size="48" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 2134.57 924)">下载</text><text fill="#FFFFFF" fill-opacity="1" font-family="Noto Sans SC Medium,Noto Sans SC Medium_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="500" font-stretch="normal" font-size="48" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 2241.71 924)">PDF</text><g><g><g><path d="M2035 882.125C2035 877.644 2038.64 874 2043.12 874L2063.44 874 2063.44 890.25C2063.44 892.497 2065.25 894.313 2067.5 894.313L2083.75 894.313 2083.75 912.594 2057.34 912.594C2052.86 912.594 2049.22 916.237 2049.22 920.719L2049.22 939 2043.12 939C2038.64 939 2035 935.357 2035 930.875L2035 882.125ZM2083.75 890.25 2067.5 890.25 2067.5 874 2083.75 890.25ZM2057.34 918.688 2061.41 918.688C2065.33 918.688 2068.52 921.874 2068.52 925.797 2068.52 929.72 2065.33 932.906 2061.41 932.906L2059.38 932.906 2059.38 936.969C2059.38 938.086 2058.46 939 2057.34 939 2056.23 939 2055.31 938.086 2055.31 936.969L2055.31 930.875 2055.31 920.719C2055.31 919.602 2056.23 918.688 2057.34 918.688ZM2061.41 928.844C2063.09 928.844 2064.45 927.486 2064.45 925.797 2064.45 924.109 2063.09 922.75 2061.41 922.75L2059.38 922.75 2059.38 928.844 2061.41 928.844ZM2073.59 918.688 2077.66 918.688C2081.02 918.688 2083.75 921.417 2083.75 924.781L2083.75 932.906C2083.75 936.271 2081.02 939 2077.66 939L2073.59 939C2072.48 939 2071.56 938.086 2071.56 936.969L2071.56 920.719C2071.56 919.602 2072.48 918.688 2073.59 918.688ZM2077.66 934.938C2078.77 934.938 2079.69 934.024 2079.69 932.906L2079.69 924.781C2079.69 923.664 2078.77 922.75 2077.66 922.75L2075.62 922.75 2075.62 934.938 2077.66 934.938ZM2087.81 920.719C2087.81 919.602 2088.73 918.688 2089.84 918.688L2095.94 918.688C2097.05 918.688 2097.97 919.602 2097.97 920.719 2097.97 921.836 2097.05 922.75 2095.94 922.75L2091.88 922.75 2091.88 926.813 2095.94 926.813C2097.05 926.813 2097.97 927.727 2097.97 928.844 2097.97 929.961 2097.05 930.875 2095.94 930.875L2091.88 930.875 2091.88 936.969C2091.88 938.086 2090.96 939 2089.84 939 2088.73 939 2087.81 938.086 2087.81 936.969L2087.81 928.844 2087.81 920.719Z" fill="#FFFFFF" fill-rule="nonzero" fill-opacity="1"/></g></g></g></g></g></svg>
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
|
@ -1 +1 @@
|
||||||
<svg width="458" height="142" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" overflow="hidden"><defs><clipPath id="clip0"><rect x="1801" y="1026" width="458" height="142"/></clipPath><clipPath id="clip1"><rect x="1801" y="1026" width="458" height="142"/></clipPath></defs><g clip-path="url(#clip0)" transform="translate(-1801 -1026)"><g clip-path="url(#clip1)"><path d="M1804 1098C1804 1061 1834 1031 1871 1031L2192 1031C2229 1031 2259 1061 2259 1098L2259 1098C2259 1135 2229 1165 2192 1165L1871 1165C1834 1165 1804 1135 1804 1098Z" fill="#52BBB1" fill-rule="evenodd" fill-opacity="0.901961"/><text fill="#3B3B3B" fill-opacity="1" font-family="Noto Sans SC Medium,Noto Sans SC Medium_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="500" font-stretch="normal" font-size="48" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 1984.07 1115)">下载</text><text fill="#3B3B3B" fill-opacity="1" font-family="Noto Sans SC Medium,Noto Sans SC Medium_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="500" font-stretch="normal" font-size="48" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 2091.21 1115)">PDF</text><g><g><g><path d="M0 7.99999C0 3.5875 3.5875 0 7.99999 0L28 0 28 16C28 18.2125 29.7875 20 32 20L48 20 48 38 22 38C17.5875 38 14 41.5875 14 46L14 63.9999 7.99999 63.9999C3.5875 63.9999 0 60.4124 0 55.9999L0 7.99999ZM48 16 32 16 32 0 48 16ZM22 44 26 44C29.8625 44 33 47.1375 33 50.9999 33 54.8624 29.8625 57.9999 26 57.9999L24 57.9999 24 61.9999C24 63.0999 23.1 63.9999 22 63.9999 20.9 63.9999 20 63.0999 20 61.9999L20 55.9999 20 46C20 44.9 20.9 44 22 44ZM26 53.9999C27.6625 53.9999 29 52.6624 29 50.9999 29 49.3375 27.6625 48 26 48L24 48 24 53.9999 26 53.9999ZM38 44 42 44C45.3125 44 48 46.6875 48 50L48 57.9999C48 61.3124 45.3125 63.9999 42 63.9999L38 63.9999C36.9 63.9999 36 63.0999 36 61.9999L36 46C36 44.9 36.9 44 38 44ZM42 59.9999C43.1 59.9999 44 59.0999 44 57.9999L44 50C44 48.9 43.1 48 42 48L40 48 40 59.9999 42 59.9999ZM51.9999 46C51.9999 44.9 52.8999 44 53.9999 44L59.9999 44C61.0999 44 61.9999 44.9 61.9999 46 61.9999 47.0999 61.0999 48 59.9999 48L55.9999 48 55.9999 51.9999 59.9999 51.9999C61.0999 51.9999 61.9999 52.8999 61.9999 53.9999 61.9999 55.0999 61.0999 55.9999 59.9999 55.9999L55.9999 55.9999 55.9999 61.9999C55.9999 63.0999 55.0999 63.9999 53.9999 63.9999 52.8999 63.9999 51.9999 63.0999 51.9999 61.9999L51.9999 53.9999 51.9999 46Z" fill="#3B3B3B" fill-rule="nonzero" fill-opacity="1" transform="matrix(1 0 0 1.01563 1884 1066)"/></g></g></g></g></g></svg>
|
<svg width="459" height="138" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" overflow="hidden"><g transform="translate(-1223 -838)"><g><path d="M1227 907C1227 869.997 1257 840 1294 840L1614 840C1651 840 1681 869.997 1681 907L1681 907C1681 944.004 1651 974.001 1614 974.001L1294 974C1257 974 1227 944.003 1227 907Z" fill="#52BBB1" fill-rule="evenodd" fill-opacity="1"/><text fill="#3B3B3B" fill-opacity="1" font-family="Noto Sans SC Medium,Noto Sans SC Medium_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="500" font-stretch="normal" font-size="48" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 1406.83 924)">下载</text><text fill="#3B3B3B" fill-opacity="1" font-family="Noto Sans SC Medium,Noto Sans SC Medium_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="500" font-stretch="normal" font-size="48" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 1513.97 924)">PDF</text><g><g><g><path d="M1307 882.125C1307 877.644 1310.64 874 1315.12 874L1335.44 874 1335.44 890.25C1335.44 892.497 1337.25 894.313 1339.5 894.313L1355.75 894.313 1355.75 912.594 1329.34 912.594C1324.86 912.594 1321.22 916.237 1321.22 920.719L1321.22 939 1315.12 939C1310.64 939 1307 935.357 1307 930.875L1307 882.125ZM1355.75 890.25 1339.5 890.25 1339.5 874 1355.75 890.25ZM1329.34 918.688 1333.41 918.688C1337.33 918.688 1340.52 921.874 1340.52 925.797 1340.52 929.72 1337.33 932.906 1333.41 932.906L1331.37 932.906 1331.37 936.969C1331.37 938.086 1330.46 939 1329.34 939 1328.23 939 1327.31 938.086 1327.31 936.969L1327.31 930.875 1327.31 920.719C1327.31 919.602 1328.23 918.688 1329.34 918.688ZM1333.41 928.844C1335.09 928.844 1336.45 927.486 1336.45 925.797 1336.45 924.109 1335.09 922.75 1333.41 922.75L1331.37 922.75 1331.37 928.844 1333.41 928.844ZM1345.59 918.688 1349.66 918.688C1353.02 918.688 1355.75 921.417 1355.75 924.781L1355.75 932.906C1355.75 936.271 1353.02 939 1349.66 939L1345.59 939C1344.48 939 1343.56 938.086 1343.56 936.969L1343.56 920.719C1343.56 919.602 1344.48 918.688 1345.59 918.688ZM1349.66 934.938C1350.77 934.938 1351.69 934.024 1351.69 932.906L1351.69 924.781C1351.69 923.664 1350.77 922.75 1349.66 922.75L1347.62 922.75 1347.62 934.938 1349.66 934.938ZM1359.81 920.719C1359.81 919.602 1360.73 918.688 1361.84 918.688L1367.94 918.688C1369.05 918.688 1369.97 919.602 1369.97 920.719 1369.97 921.836 1369.05 922.75 1367.94 922.75L1363.87 922.75 1363.87 926.813 1367.94 926.813C1369.05 926.813 1369.97 927.727 1369.97 928.844 1369.97 929.961 1369.05 930.875 1367.94 930.875L1363.87 930.875 1363.87 936.969C1363.87 938.086 1362.96 939 1361.84 939 1360.73 939 1359.81 938.086 1359.81 936.969L1359.81 928.844 1359.81 920.719Z" fill="#3B3B3B" fill-rule="nonzero" fill-opacity="1"/></g></g></g></g></g></svg>
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.9 KiB |
1
docs/index.assets/btn_english_edition.svg
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<svg width="458" height="142" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" overflow="hidden"><g transform="translate(-1952 -1242)"><g><path d="M1954 1313C1954 1276 1984 1246 2021 1246L2342 1246C2379 1246 2409 1276 2409 1313L2409 1313C2409 1350 2379 1380 2342 1380L2021 1380C1984 1380 1954 1350 1954 1313Z" fill="#55AEA6" fill-rule="evenodd" fill-opacity="1"/><text fill="#FFFFFF" fill-opacity="1" font-family="Noto Sans SC,Noto Sans SC_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="700" font-stretch="normal" font-size="41" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 2132.59 1328)">English Ed</text><text fill="#FFFFFF" fill-opacity="1" font-family="Noto Sans SC,Noto Sans SC_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="700" font-stretch="normal" font-size="41" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 2342.28 1328)">.</text><g><g><g><path d="M0 17.2001C0 12.4566 3.85658 8.60003 8.60003 8.60003L34.4001 8.60003 40.8501 8.60003 43.0001 8.60003 77.4003 8.60003C82.1437 8.60003 86.0003 12.4566 86.0003 17.2001L86.0003 51.6002C86.0003 56.3436 82.1437 60.2002 77.4003 60.2002L43.0001 60.2002 40.8501 60.2002 34.4001 60.2002 8.60003 60.2002C3.85658 60.2002 0 56.3436 0 51.6002L0 17.2001ZM43.0001 17.2001 43.0001 51.6002 77.4003 51.6002 77.4003 17.2001 43.0001 17.2001ZM23.9591 23.6366C23.5291 22.6691 22.5616 22.0376 21.5001 22.0376 20.4385 22.0376 19.471 22.6691 19.041 23.6366L10.441 42.9867C9.83628 44.3439 10.4544 45.9295 11.8116 46.5342 13.1688 47.1389 14.7544 46.5208 15.3591 45.1636L16.5551 42.4626 26.4451 42.4626 27.641 45.1636C28.2457 46.5208 29.8314 47.1255 31.1885 46.5342 32.5457 45.943 33.1504 44.3439 32.5592 42.9867L23.9591 23.6366ZM21.5001 31.3364 24.0532 37.0876 18.9469 37.0876 21.5001 31.3364ZM60.2002 22.0376C61.6783 22.0376 62.8877 23.247 62.8877 24.7251L62.8877 25.2626 68.8002 25.2626 70.9502 25.2626C72.4284 25.2626 73.6378 26.472 73.6378 27.9501 73.6378 29.4282 72.4284 30.6376 70.9502 30.6376L70.6815 30.6376 70.4665 31.2423C69.2706 34.5211 67.4565 37.5042 65.1452 40.0305 65.2662 40.1111 65.3871 40.1783 65.508 40.2455L68.0477 41.7639C69.3243 42.5298 69.7274 44.1827 68.9749 45.4458 68.2224 46.7089 66.5562 47.1255 65.293 46.373L62.7533 44.8545C62.1487 44.4917 61.5708 44.1155 60.993 43.7123 59.5686 44.7202 58.0502 45.5936 56.4243 46.3192L55.9405 46.5342C54.5833 47.1389 52.9977 46.5208 52.393 45.1636 51.7883 43.8064 52.4064 42.2208 53.7636 41.6161L54.2474 41.4011C55.1074 41.0114 55.9405 40.5814 56.7333 40.0842L55.0939 38.4448C54.0458 37.3967 54.0458 35.6901 55.0939 34.642 56.1421 33.5939 57.8486 33.5939 58.8968 34.642L60.8587 36.6039 60.9258 36.6711C62.5921 34.9107 63.9493 32.8682 64.9302 30.6242L60.2002 30.6242 50.5252 30.6242C49.047 30.6242 47.8377 29.4148 47.8377 27.9367 47.8377 26.4585 49.047 25.2491 50.5252 25.2491L57.5127 25.2491 57.5127 24.7116C57.5127 23.2335 58.7221 22.0241 60.2002 22.0241Z" fill="#FFFFFF" fill-rule="nonzero" fill-opacity="1" transform="matrix(1 0 0 1.0029 2019 1278)"/></g></g></g></g></g></svg>
|
After Width: | Height: | Size: 3.2 KiB |
1
docs/index.assets/btn_english_edition_dark.svg
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<svg width="459" height="142" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" overflow="hidden"><g transform="translate(-1223 -1242)"><g><path d="M1227 1313C1227 1276 1257 1246 1294 1246L1614 1246C1651 1246 1681 1276 1681 1313L1681 1313C1681 1350 1651 1380 1614 1380L1294 1380C1257 1380 1227 1350 1227 1313Z" fill="#52BBB1" fill-rule="evenodd" fill-opacity="1"/><text fill="#3B3B3B" fill-opacity="1" font-family="Noto Sans SC,Noto Sans SC_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="700" font-stretch="normal" font-size="41" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 1404.85 1328)">English Ed</text><text fill="#3B3B3B" fill-opacity="1" font-family="Noto Sans SC,Noto Sans SC_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="700" font-stretch="normal" font-size="41" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 1614.54 1328)">.</text><g><g><g><path d="M0 17.2C0 12.4566 3.85656 8.59999 8.59999 8.59999L34.4 8.59999 40.85 8.59999 43 8.59999 77.3999 8.59999C82.1434 8.59999 85.9999 12.4566 85.9999 17.2L85.9999 51.6C85.9999 56.3434 82.1434 60.2 77.3999 60.2L43 60.2 40.85 60.2 34.4 60.2 8.59999 60.2C3.85656 60.2 0 56.3434 0 51.6L0 17.2ZM43 17.2 43 51.6 77.3999 51.6 77.3999 17.2 43 17.2ZM23.959 23.6365C23.529 22.669 22.5615 22.0375 21.5 22.0375 20.4384 22.0375 19.4709 22.669 19.0409 23.6365L10.4409 42.9865C9.83624 44.3437 10.4544 45.9293 11.8116 46.534 13.1687 47.1387 14.7544 46.5206 15.3591 45.1634L16.555 42.4625 26.445 42.4625 27.6409 45.1634C28.2456 46.5206 29.8312 47.1253 31.1884 46.534 32.5456 45.9428 33.1503 44.3437 32.559 42.9865L23.959 23.6365ZM21.5 31.3362 24.0531 37.0875 18.9469 37.0875 21.5 31.3362ZM60.2 22.0375C61.6781 22.0375 62.8875 23.2469 62.8875 24.725L62.8875 25.2625 68.7999 25.2625 70.95 25.2625C72.4281 25.2625 73.6374 26.4719 73.6374 27.95 73.6374 29.4281 72.4281 30.6375 70.95 30.6375L70.6812 30.6375 70.4662 31.2422C69.2703 34.5209 67.4562 37.504 65.145 40.0303 65.2659 40.1109 65.3868 40.1781 65.5078 40.2453L68.0474 41.7637C69.324 42.5297 69.7271 44.1825 68.9746 45.4456 68.2221 46.7087 66.5559 47.1253 65.2928 46.3728L62.7531 44.8543C62.1484 44.4915 61.5706 44.1153 60.9928 43.7122 59.5684 44.72 58.05 45.5934 56.424 46.319L55.9403 46.534C54.5831 47.1387 52.9975 46.5206 52.3928 45.1634 51.7881 43.8062 52.4062 42.2206 53.7634 41.6159L54.2472 41.4009C55.1071 41.0112 55.9403 40.5812 56.7331 40.084L55.0937 38.4447C54.0456 37.3965 54.0456 35.69 55.0937 34.6418 56.1418 33.5937 57.8484 33.5937 58.8965 34.6418L60.8584 36.6037 60.9256 36.6709C62.5918 34.9106 63.949 32.8681 64.93 30.624L60.2 30.624 50.525 30.624C49.0468 30.624 47.8375 29.4147 47.8375 27.9365 47.8375 26.4584 49.0468 25.249 50.525 25.249L57.5125 25.249 57.5125 24.7115C57.5125 23.2334 58.7218 22.024 60.2 22.024Z" fill="#3B3B3B" fill-rule="nonzero" fill-opacity="1" transform="matrix(1 0 0 1.00291 1291 1278)"/></g></g></g></g></g></svg>
|
After Width: | Height: | Size: 3.1 KiB |
|
@ -1 +1 @@
|
||||||
<svg width="463" height="142" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" overflow="hidden"><g transform="translate(-2493 -825)"><g><path d="M2497 896C2497 858.997 2527 829 2564 829L2885 829C2922 829 2952 858.997 2952 896L2952 896C2952 933.003 2922 963 2885 963L2564 963C2527 963 2497 933.003 2497 896Z" fill="#52BBB1" fill-rule="evenodd" fill-opacity="0.901961"/><text fill="#FFFFFF" fill-opacity="1" font-family="Noto Sans SC Medium,Noto Sans SC Medium_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="500" font-stretch="normal" font-size="48" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 2680.99 912)">在线阅读</text><g><g><g><path d="M16.2 0C11.7324 0 8.10001 3.63235 8.10001 8.10001L8.10001 36.4501 2.43 36.4501C1.08844 36.4501 0 37.5385 0 38.8801 0 44.2463 4.35376 48.6001 9.72002 48.6001L40.5001 48.6001 40.5001 36.4501 16.2 36.4501 16.2 8.10001 56.7001 8.10001 56.7001 12.15 64.8001 12.15 64.8001 8.10001C64.8001 3.63235 61.1678 0 56.7001 0L16.2 0ZM64.8001 16.2 50.6251 16.2C47.2712 16.2 44.5501 18.9211 44.5501 22.275L44.5501 58.7251C44.5501 62.079 47.2712 64.8001 50.6251 64.8001L74.9251 64.8001C78.279 64.8001 81.0001 62.079 81.0001 58.7251L81.0001 32.4001 68.8501 32.4001C66.6099 32.4001 64.8001 30.5902 64.8001 28.35L64.8001 16.2ZM68.8501 16.2 68.8501 28.35 81.0001 28.35 68.8501 16.2Z" fill="#FFFFFF" fill-rule="nonzero" fill-opacity="1" transform="matrix(1 0 0 1.00308 2564 865)"/></g></g></g></g></g></svg>
|
<svg width="458" height="142" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" overflow="hidden"><g transform="translate(-2493 -825)"><g><path d="M2497 896C2497 858.997 2527 829 2564 829L2885 829C2922 829 2952 858.997 2952 896L2952 896C2952 933.003 2922 963 2885 963L2564 963C2527 963 2497 933.003 2497 896Z" fill="#52BBB1" fill-rule="evenodd" fill-opacity="0.901961"/><text fill="#FFFFFF" fill-opacity="1" font-family="Noto Sans SC Medium,Noto Sans SC Medium_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="500" font-stretch="normal" font-size="48" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 2680.99 912)">在线阅读</text><g><g><g><path d="M16.2 0C11.7324 0 8.10001 3.63235 8.10001 8.10001L8.10001 36.4501 2.43 36.4501C1.08844 36.4501 0 37.5385 0 38.8801 0 44.2463 4.35376 48.6001 9.72002 48.6001L40.5001 48.6001 40.5001 36.4501 16.2 36.4501 16.2 8.10001 56.7001 8.10001 56.7001 12.15 64.8001 12.15 64.8001 8.10001C64.8001 3.63235 61.1678 0 56.7001 0L16.2 0ZM64.8001 16.2 50.6251 16.2C47.2712 16.2 44.5501 18.9211 44.5501 22.275L44.5501 58.7251C44.5501 62.079 47.2712 64.8001 50.6251 64.8001L74.9251 64.8001C78.279 64.8001 81.0001 62.079 81.0001 58.7251L81.0001 32.4001 68.8501 32.4001C66.6099 32.4001 64.8001 30.5902 64.8001 28.35L64.8001 16.2ZM68.8501 16.2 68.8501 28.35 81.0001 28.35 68.8501 16.2Z" fill="#FFFFFF" fill-rule="nonzero" fill-opacity="1" transform="matrix(1 0 0 1.00308 2564 865)"/></g></g></g></g></g></svg>
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
|
@ -1 +1 @@
|
||||||
<svg width="458" height="142" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" overflow="hidden"><defs><clipPath id="clip0"><rect x="1801" y="825" width="458" height="142"/></clipPath><clipPath id="clip1"><rect x="1801" y="825" width="458" height="142"/></clipPath></defs><g clip-path="url(#clip0)" transform="translate(-1801 -825)"><g clip-path="url(#clip1)"><path d="M1804 896C1804 858.997 1834 829 1871 829L2192 829C2229 829 2259 858.997 2259 896L2259 896C2259 933.003 2229 963 2192 963L1871 963C1834 963 1804 933.003 1804 896Z" fill="#52BBB1" fill-rule="evenodd" fill-opacity="0.901961"/><text fill="#3B3B3B" fill-opacity="1" font-family="Noto Sans SC Medium,Noto Sans SC Medium_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="500" font-stretch="normal" font-size="48" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 1987.51 912)">在线阅读</text><g><g><g><path d="M16.2 0C11.7324 0 8.10001 3.63235 8.10001 8.10001L8.10001 36.4501 2.43 36.4501C1.08844 36.4501 0 37.5385 0 38.8801 0 44.2463 4.35376 48.6001 9.72002 48.6001L40.5001 48.6001 40.5001 36.4501 16.2 36.4501 16.2 8.10001 56.7001 8.10001 56.7001 12.15 64.8001 12.15 64.8001 8.10001C64.8001 3.63235 61.1678 0 56.7001 0L16.2 0ZM64.8001 16.2 50.6251 16.2C47.2712 16.2 44.5501 18.9211 44.5501 22.275L44.5501 58.7251C44.5501 62.079 47.2712 64.8001 50.6251 64.8001L74.9251 64.8001C78.279 64.8001 81.0001 62.079 81.0001 58.7251L81.0001 32.4001 68.8501 32.4001C66.6099 32.4001 64.8001 30.5902 64.8001 28.35L64.8001 16.2ZM68.8501 16.2 68.8501 28.35 81.0001 28.35 68.8501 16.2Z" fill="#3B3B3B" fill-rule="nonzero" fill-opacity="1" transform="matrix(1 0 0 1.00308 1871 865)"/></g></g></g></g></g></svg>
|
<svg width="459" height="142" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" overflow="hidden"><defs><clipPath id="clip0"><rect x="1292" y="672" width="83" height="65"/></clipPath><clipPath id="clip1"><rect x="1292" y="672" width="83" height="65"/></clipPath><clipPath id="clip2"><rect x="1292" y="672" width="83" height="65"/></clipPath></defs><g transform="translate(-1223 -632)"><g><path d="M1227 704C1227 666.997 1257 637 1294 637L1614 637C1651 637 1681 666.997 1681 704L1681 704C1681 741.003 1651 771 1614 771L1294 771C1257 771 1227 741.003 1227 704Z" fill="#52BBB1" fill-rule="evenodd" fill-opacity="1"/><text fill="#3B3B3B" fill-opacity="1" font-family="Noto Sans SC Medium,Noto Sans SC Medium_MSFontService,sans-serif" font-style="normal" font-variant="normal" font-weight="500" font-stretch="normal" font-size="48" text-anchor="start" direction="ltr" writing-mode="lr-tb" unicode-bidi="normal" text-decoration="none" transform="matrix(1 0 0 1 1410.27 721)">在线阅读</text><g clip-path="url(#clip0)"><g clip-path="url(#clip1)"><g clip-path="url(#clip2)"><path d="M16.25 0C11.7685 0 8.125 3.64355 8.125 8.125L8.125 36.5625 2.4375 36.5625C1.0918 36.5625 0 37.6543 0 39 0 44.3828 4.36719 48.75 9.75 48.75L40.625 48.75 40.625 36.5625 16.25 36.5625 16.25 8.125 56.875 8.125 56.875 12.1875 65 12.1875 65 8.125C65 3.64355 61.3564 0 56.875 0L16.25 0ZM65 16.25 50.7812 16.25C47.417 16.25 44.6875 18.9795 44.6875 22.3437L44.6875 58.9062C44.6875 62.2705 47.417 65 50.7812 65L75.1562 65C78.5205 65 81.25 62.2705 81.25 58.9062L81.25 32.5 69.0625 32.5C66.8154 32.5 65 30.6846 65 28.4375L65 16.25ZM69.0625 16.25 69.0625 28.4375 81.25 28.4375 69.0625 16.25Z" fill="#3B3B3B" fill-rule="nonzero" fill-opacity="1" transform="matrix(1.00923 0 0 1 1293 672)"/></g></g></g></g></g></svg>
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
164
mkdocs-en.yml
Normal file
|
@ -0,0 +1,164 @@
|
||||||
|
# Config inheritance
|
||||||
|
INHERIT: mkdocs.yml
|
||||||
|
|
||||||
|
# Project information
|
||||||
|
site_name: Hello Algo
|
||||||
|
site_url: https://www.hello-algo.com/en/
|
||||||
|
site_description: "Data Structures and Algorithms Crash Course with Animated Illustrations and Off-the-Shelf Code"
|
||||||
|
docs_dir: build/docs-en
|
||||||
|
site_dir: site/en
|
||||||
|
# Repository
|
||||||
|
edit_uri: tree/main/docs-en
|
||||||
|
version: 1.0.0b6
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
theme:
|
||||||
|
language: en
|
||||||
|
font:
|
||||||
|
text: Roboto
|
||||||
|
code: Fira Code
|
||||||
|
|
||||||
|
extra:
|
||||||
|
status:
|
||||||
|
new: Recently Added
|
||||||
|
|
||||||
|
# Page tree
|
||||||
|
nav:
|
||||||
|
- Chapter 0. Preface:
|
||||||
|
# [icon: material/book-open-outline]
|
||||||
|
- chapter_preface/index.md
|
||||||
|
- 0.1 The Book: chapter_preface/about_the_book.md
|
||||||
|
- 0.2 How to Read: chapter_preface/suggestions.md
|
||||||
|
- 0.3 Summary: chapter_preface/summary.md
|
||||||
|
- Chapter 1. Introduction to Algorithms:
|
||||||
|
# [icon: material/calculator-variant-outline]
|
||||||
|
- chapter_introduction/index.md
|
||||||
|
- 1.1 Algorithms Are Everywhere: chapter_introduction/algorithms_are_everywhere.md
|
||||||
|
- 1.2 What is Algorithms: chapter_introduction/what_is_dsa.md
|
||||||
|
- 1.3 Summary: chapter_introduction/summary.md
|
||||||
|
- Chapter 2. Computational Complexity:
|
||||||
|
# [icon: material/timer-sand]
|
||||||
|
- chapter_computational_complexity/index.md
|
||||||
|
- 2.1 Evaluating Algorithm Efficiency: chapter_computational_complexity/performance_evaluation.md
|
||||||
|
- 2.2 Iteration and Recursion: chapter_computational_complexity/iteration_and_recursion.md
|
||||||
|
- 2.3 Time Complexity: chapter_computational_complexity/time_complexity.md
|
||||||
|
- 2.4 Space Complexity: chapter_computational_complexity/space_complexity.md
|
||||||
|
- 2.5 Summary: chapter_computational_complexity/summary.md
|
||||||
|
# - Chapter 3. Data Structure:
|
||||||
|
# # [icon: material/shape-outline]
|
||||||
|
# - chapter_data_structure/index.md
|
||||||
|
# - 3.1 Classification of Data Structure: chapter_data_structure/classification_of_data_structure.md
|
||||||
|
# - 3.2 Basic Data Types: chapter_data_structure/basic_data_types.md
|
||||||
|
# - 3.3 Number Encoding *: chapter_data_structure/number_encoding.md
|
||||||
|
# - 3.4 Character Encoding *: chapter_data_structure/character_encoding.md
|
||||||
|
# - 3.5 Summary: chapter_data_structure/summary.md
|
||||||
|
# - Chapter 4. Array and Linked List:
|
||||||
|
# # [icon: material/view-list-outline]
|
||||||
|
# - chapter_array_and_linkedlist/index.md
|
||||||
|
# - 4.1 Array: chapter_array_and_linkedlist/array.md
|
||||||
|
# - 4.2 Linked List: chapter_array_and_linkedlist/linked_list.md
|
||||||
|
# - 4.3 List: chapter_array_and_linkedlist/list.md
|
||||||
|
# - 4.4 Summary: chapter_array_and_linkedlist/summary.md
|
||||||
|
# - Chapter 5. Stack and Queue:
|
||||||
|
# # [icon: material/stack-overflow]
|
||||||
|
# - chapter_stack_and_queue/index.md
|
||||||
|
# - 5.1 Stack: chapter_stack_and_queue/stack.md
|
||||||
|
# - 5.2 Queue: chapter_stack_and_queue/queue.md
|
||||||
|
# - 5.3 Double-ended Queue: chapter_stack_and_queue/deque.md
|
||||||
|
# - 5.4 Summary: chapter_stack_and_queue/summary.md
|
||||||
|
# - Chapter 6. Hash Table:
|
||||||
|
# # [icon: material/table-search]
|
||||||
|
# - chapter_hashing/index.md
|
||||||
|
# - 6.1 Hash Table: chapter_hashing/hash_map.md
|
||||||
|
# - 6.2 Hash Collision: chapter_hashing/hash_collision.md
|
||||||
|
# - 6.3 Hash Algorithm: chapter_hashing/hash_algorithm.md
|
||||||
|
# - 6.4 Summary: chapter_hashing/summary.md
|
||||||
|
# - Chapter 7. Tree:
|
||||||
|
# # [icon: material/graph-outline]
|
||||||
|
# - chapter_tree/index.md
|
||||||
|
# - 7.1 Binary Tree: chapter_tree/binary_tree.md
|
||||||
|
# - 7.2 Binary Tree Traversal: chapter_tree/binary_tree_traversal.md
|
||||||
|
# - 7.3 Array Representation of Tree: chapter_tree/array_representation_of_tree.md
|
||||||
|
# - 7.4 Binary Search Tree: chapter_tree/binary_search_tree.md
|
||||||
|
# - 7.5 AVL Tree *: chapter_tree/avl_tree.md
|
||||||
|
# - 7.6 Summary: chapter_tree/summary.md
|
||||||
|
# - Chapter 8. Heap:
|
||||||
|
# # [icon: material/family-tree]
|
||||||
|
# - chapter_heap/index.md
|
||||||
|
# - 8.1 Heap: chapter_heap/heap.md
|
||||||
|
# - 8.2 Building a Heap: chapter_heap/build_heap.md
|
||||||
|
# - 8.3 Top-K Problem: chapter_heap/top_k.md
|
||||||
|
# - 8.4 Summary: chapter_heap/summary.md
|
||||||
|
# - Chapter 9. Graph:
|
||||||
|
# # [icon: material/graphql]
|
||||||
|
# - chapter_graph/index.md
|
||||||
|
# - 9.1 Graph: chapter_graph/graph.md
|
||||||
|
# - 9.2 Basic Graph Operations: chapter_graph/graph_operations.md
|
||||||
|
# - 9.3 Graph Traversal: chapter_graph/graph_traversal.md
|
||||||
|
# - 9.4 Summary: chapter_graph/summary.md
|
||||||
|
# - Chapter 10. Searching:
|
||||||
|
# # [icon: material/text-search]
|
||||||
|
# - chapter_searching/index.md
|
||||||
|
# - 10.1 Binary Search: chapter_searching/binary_search.md
|
||||||
|
# - 10.2 Binary Search Insertion Point: chapter_searching/binary_search_insertion.md
|
||||||
|
# - 10.3 Binary Search Boundaries: chapter_searching/binary_search_edge.md
|
||||||
|
# - 10.4 Hashing Optimization Strategy: chapter_searching/replace_linear_by_hashing.md
|
||||||
|
# - 10.5 Revisiting Search Algorithms: chapter_searching/searching_algorithm_revisited.md
|
||||||
|
# - 10.6 Summary: chapter_searching/summary.md
|
||||||
|
# - Chapter 11. Sorting:
|
||||||
|
# # [icon: material/sort-ascending]
|
||||||
|
# - chapter_sorting/index.md
|
||||||
|
# - 11.1 Sorting Algorithms: chapter_sorting/sorting_algorithm.md
|
||||||
|
# - 11.2 Selection Sort: chapter_sorting/selection_sort.md
|
||||||
|
# - 11.3 Bubble Sort: chapter_sorting/bubble_sort.md
|
||||||
|
# - 11.4 Insertion Sort: chapter_sorting/insertion_sort.md
|
||||||
|
# - 11.5 Quick Sort: chapter_sorting/quick_sort.md
|
||||||
|
# - 11.6 Merge Sort: chapter_sorting/merge_sort.md
|
||||||
|
# - 11.7 Heap Sort: chapter_sorting/heap_sort.md
|
||||||
|
# - 11.8 Bucket Sort: chapter_sorting/bucket_sort.md
|
||||||
|
# - 11.9 Counting Sort: chapter_sorting/counting_sort.md
|
||||||
|
# - 11.10 Radix Sort: chapter_sorting/radix_sort.md
|
||||||
|
# - 11.11 Summary: chapter_sorting/summary.md
|
||||||
|
# - Chapter 12. Divide and Conquer:
|
||||||
|
# # [icon: material/set-split]
|
||||||
|
# - chapter_divide_and_conquer/index.md
|
||||||
|
# - 12.1 Divide and Conquer Algorithm: chapter_divide_and_conquer/divide_and_conquer.md
|
||||||
|
# - 12.2 Divide and Conquer Search Strategy: chapter_divide_and_conquer/binary_search_recur.md
|
||||||
|
# - 12.3 Building Tree Problems: chapter_divide_and_conquer/build_binary_tree_problem.md
|
||||||
|
# - 12.4 Tower of Hanoi Problem: chapter_divide_and_conquer/hanota_problem.md
|
||||||
|
# - 12.5 Summary: chapter_divide_and_conquer/summary.md
|
||||||
|
# - Chapter 13. Backtracking:
|
||||||
|
# # [icon: material/map-marker-path]
|
||||||
|
# - chapter_backtracking/index.md
|
||||||
|
# - 13.1 Backtracking Algorithm: chapter_backtracking/backtracking_algorithm.md
|
||||||
|
# - 13.2 Permutations Problem: chapter_backtracking/permutations_problem.md
|
||||||
|
# - 13.3 Subset Sum Problem: chapter_backtracking/subset_sum_problem.md
|
||||||
|
# - 13.4 N-Queens Problem: chapter_backtracking/n_queens_problem.md
|
||||||
|
# - 13.5 Summary: chapter_backtracking/summary.md
|
||||||
|
# - Chapter 14. Dynamic Programming:
|
||||||
|
# # [icon: material/table-pivot]
|
||||||
|
# - chapter_dynamic_programming/index.md
|
||||||
|
# - 14.1 Introduction to Dynamic Programming: chapter_dynamic_programming/intro_to_dynamic_programming.md
|
||||||
|
# - 14.2 Features of DP Problems: chapter_dynamic_programming/dp_problem_features.md
|
||||||
|
# - 14.3 DP Solution Approach: chapter_dynamic_programming/dp_solution_pipeline.md
|
||||||
|
# - 14.4 0-1 Knapsack Problem: chapter_dynamic_programming/knapsack_problem.md
|
||||||
|
# - 14.5 Unbounded Knapsack Problem: chapter_dynamic_programming/unbounded_knapsack_problem.md
|
||||||
|
# - 14.6 Edit Distance Problem: chapter_dynamic_programming/edit_distance_problem.md
|
||||||
|
# - 14.7 Summary: chapter_dynamic_programming/summary.md
|
||||||
|
# - Chapter 15. Greedy:
|
||||||
|
# # [icon: material/head-heart-outline]
|
||||||
|
# - chapter_greedy/index.md
|
||||||
|
# - 15.1 Greedy Algorithm: chapter_greedy/greedy_algorithm.md
|
||||||
|
# - 15.2 Fractional Knapsack Problem: chapter_greedy/fractional_knapsack_problem.md
|
||||||
|
# - 15.3 Maximum Capacity Problem: chapter_greedy/max_capacity_problem.md
|
||||||
|
# - 15.4 Maximum Product Cutting Problem: chapter_greedy/max_product_cutting_problem.md
|
||||||
|
# - 15.5 Summary: chapter_greedy/summary.md
|
||||||
|
# - Chapter 16. Appendix:
|
||||||
|
# # [icon: material/help-circle-outline]
|
||||||
|
# - chapter_appendix/index.md
|
||||||
|
# - 16.1 Installation of Programming Environment: chapter_appendix/installation.md
|
||||||
|
# - 16.2 Contributing to the Creation: chapter_appendix/contribution.md
|
||||||
|
# # [status: new]
|
||||||
|
# - 16.3 Terminology: chapter_appendix/terminology.md
|
||||||
|
# - References:
|
||||||
|
# - chapter_reference/index.md
|
|
@ -71,9 +71,9 @@ extra:
|
||||||
- name: 中文
|
- name: 中文
|
||||||
link: /
|
link: /
|
||||||
lang: zh
|
lang: zh
|
||||||
# - name: English
|
- name: English
|
||||||
# link: /en/
|
link: /en/
|
||||||
# lang: en
|
lang: en
|
||||||
social:
|
social:
|
||||||
- icon: fontawesome/brands/github
|
- icon: fontawesome/brands/github
|
||||||
link: https://github.com/krahets
|
link: https://github.com/krahets
|
||||||
|
|