Skip to content

Commit

Permalink
Updated answer 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxinyu95 committed May 4, 2023
1 parent aedee63 commit 868ecdc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This book introduces about elementary algorithms and data structure. It includes
Contents
--------

I am adding exercises and answers to the **second edition** from 2023/03. I wrote the first edition from 2009 to 2017, then rewrote from 2020 to 2023. The PDF can be downloaded for preview ([EN](https://github.com/liuxinyu95/AlgoXY/files/11378652/algoxy-en.pdf), [中文](https://github.com/liuxinyu95/AlgoXY/files/11378653/algoxy-zh-cn.pdf)). The 1st edition in Chinese ([中文](http://www.ituring.com.cn/book/1907)) was published in 2017. I recently switched my focus to the Mathematics of programming, the new book is also available in ([github](https://github.com/liuxinyu95/unplugged))
I am adding exercises and answers to the **second edition** from 2023/03 (added 119 answers as of 2023/05). I wrote the first edition from 2009 to 2017, then rewrote from 2020 to 2023. The PDF can be downloaded for preview ([EN](https://github.com/liuxinyu95/AlgoXY/files/11378652/algoxy-en.pdf), [中文](https://github.com/liuxinyu95/AlgoXY/files/11378653/algoxy-zh-cn.pdf)). The 1st edition in Chinese ([中文](http://www.ituring.com.cn/book/1907)) was published in 2017. I recently switched my focus to the Mathematics of programming, the new book is also available in ([github](https://github.com/liuxinyu95/unplugged))


- Preface
Expand Down
10 changes: 5 additions & 5 deletions others/preface/preface-en.tex
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,14 @@ \section*{Summary}
\begin{Bourbaki}
Int minFree([Int] nums) {
var n = length(nums)
for Int i = 0 to n {
for Int i = 0 to n - 1 {
var k = abs(nums[i])
if k <= n then nums[k - 1] = -abs(nums[k - 1])
if k < n then nums[k] = -abs(nums[k])
}
for Int i = 0 to n {
if nums[i] > 0 then return i + 1
for Int i = 0 to n - 1 {
if nums[i] > 0 then return i
}
return n + 1
return n
}
\end{Bourbaki}
}
Expand Down
14 changes: 7 additions & 7 deletions others/preface/preface-zh-cn.tex
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ \subsection*{队列}
算法循环$n$次。每次从三个队列中取出最小元素,这一步需要常数时间。接着根据取出元素所在的队列,产生一到三个新数加入队列,这一步也是常数时间。整个算法复杂度为$O(n)$

\section*{小结}
尽管两道趣题都能用穷举法解决,但随着规模增加,我们不得不寻求更好的解法。本书\textbf{不是}一本算法竞赛或面试的“刷题手册”。本书介绍常见的基本算法和数据结构,对比给出纯函数式和命令式实现,展示函数式算法和数据结构的特有思路。主要参考了冈崎的著作\cite{okasaki-book}和经典的算法教材\cite{CLRS}。本书尽量避免依赖于特定的编程语言。一方面读者会有自己的偏好,另一方面编程语言也在不断变化。为此我们主要使用伪代码和数学记法对算法进行定义,并附以一些例子代码。函数式的示例类似Haskell,命令式的示例是几种语言的混合体。
尽管两道趣题都能用穷举法解决,但随着规模增加,我们不得不寻求更好的解法。本书\textbf{不是}一本算法竞赛或面试的“刷题手册”。本书介绍常见的基本算法和数据结构,对比给出纯函数式和命令式实现,展示函数式算法和数据结构的特有思路。主要参考了冈崎的著作\cite{okasaki-book}和经典的算法教材\cite{CLRS}。本书尽量避免依赖于特定的编程语言。一方面读者会有自己的偏好,另一方面编程语言也在不断变化。我们主要使用伪代码和数学记法对算法进行定义,并附以一些例子代码。函数式的示例类似Haskell,命令式的示例是几种语言的混合体。

本书中文版《算法新解》从2009年开始写作,2017年出版。2020年底开始重写,2023年5月完成了第二版,并增加了119道习题的答案。电子版可以在github上获得,如果希望获得纸质版,请在github上联系我。
本书中文版《算法新解》从2009年开始写作,2017年出版。2020年底开始重写,2023年5月完成了第二版,并增加了119道习题答案。电子版可以在github上获得,如果希望获得纸质版,请在github上联系我。

\begin{Exercise}\label{ex:preface}
\Question{最小可用数趣题中,所有数都是非负整数。我们可以利用正负号来标记一个数字是否存在。首先扫描一遍列表,令列表长度为$n$,对于任何绝对值小于$n$的数$|x| < n$,将位置$|x|$上的数字置为负数。之后再次扫描一遍列表,找到第一个正数所在的位置就是答案。编程实现这一算法。}
Expand Down Expand Up @@ -363,14 +363,14 @@ \section*{小结}
\begin{Bourbaki}
Int minFree([Int] nums) {
var n = length(nums)
for Int i = 0 to n {
for Int i = 0 to n - 1 {
var k = abs(nums[i])
if k <= n then nums[k - 1] = -abs(nums[k - 1])
if k < n then nums[k] = -abs(nums[k])
}
for Int i = 0 to n {
if nums[i] > 0 then return i + 1
for Int i = 0 to n - 1 {
if nums[i] > 0 then return i
}
return n + 1
return n
}
\end{Bourbaki}
}
Expand Down

0 comments on commit 868ecdc

Please sign in to comment.