Bug fixes
This commit is contained in:
parent
d61838a4eb
commit
d1f307e547
@ -9,7 +9,6 @@ class QuickSort
|
|||||||
class << self
|
class << self
|
||||||
### 哨兵划分 ###
|
### 哨兵划分 ###
|
||||||
def partition(nums, left, right)
|
def partition(nums, left, right)
|
||||||
|
|
||||||
# 以 nums[left] 为基准数
|
# 以 nums[left] 为基准数
|
||||||
i, j = left, right
|
i, j = left, right
|
||||||
while i < j
|
while i < j
|
||||||
@ -116,7 +115,7 @@ class QuickSortTailCall
|
|||||||
i # 返回基准数的索引
|
i # 返回基准数的索引
|
||||||
end
|
end
|
||||||
|
|
||||||
### 快速排序(尾递归优化)
|
### 快速排序(尾递归优化)###
|
||||||
def quick_sort(nums, left, right)
|
def quick_sort(nums, left, right)
|
||||||
# 子数组长度不为 1 时递归
|
# 子数组长度不为 1 时递归
|
||||||
while left < right
|
while left < right
|
||||||
|
|||||||
@ -729,8 +729,8 @@ Let the size of the input data be $n$, the following chart displays common types
|
|||||||
|
|
||||||
$$
|
$$
|
||||||
\begin{aligned}
|
\begin{aligned}
|
||||||
O(1) < O(\log n) < O(n) < O(n^2) < O(2^n) \newline
|
& O(1) < O(\log n) < O(n) < O(n^2) < O(2^n) \newline
|
||||||
\text{Constant Order} < \text{Logarithmic Order} < \text{Linear Order} < \text{Quadratic Order} < \text{Exponential Order}
|
& \text{Constant} < \text{Logarithmic} < \text{Linear} < \text{Quadratic} < \text{Exponential}
|
||||||
\end{aligned}
|
\end{aligned}
|
||||||
$$
|
$$
|
||||||
|
|
||||||
|
|||||||
@ -955,8 +955,8 @@ Let's consider the input data size as $n$. The common types of time complexities
|
|||||||
|
|
||||||
$$
|
$$
|
||||||
\begin{aligned}
|
\begin{aligned}
|
||||||
O(1) < O(\log n) < O(n) < O(n \log n) < O(n^2) < O(2^n) < O(n!) \newline
|
& O(1) < O(\log n) < O(n) < O(n \log n) < O(n^2) < O(2^n) < O(n!) \newline
|
||||||
\text{Constant Order} < \text{Logarithmic Order} < \text{Linear Order} < \text{Linear-Logarithmic Order} < \text{Quadratic Order} < \text{Exponential Order} < \text{Factorial Order}
|
& \text{Constant} < \text{Log} < \text{Linear} < \text{Linear-Log} < \text{Quadratic} < \text{Exp} < \text{Factorial}
|
||||||
\end{aligned}
|
\end{aligned}
|
||||||
$$
|
$$
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,6 @@ class QuickSort
|
|||||||
class << self
|
class << self
|
||||||
### 哨兵劃分 ###
|
### 哨兵劃分 ###
|
||||||
def partition(nums, left, right)
|
def partition(nums, left, right)
|
||||||
|
|
||||||
# 以 nums[left] 為基準數
|
# 以 nums[left] 為基準數
|
||||||
i, j = left, right
|
i, j = left, right
|
||||||
while i < j
|
while i < j
|
||||||
@ -116,7 +115,7 @@ class QuickSortTailCall
|
|||||||
i # 返回基準數的索引
|
i # 返回基準數的索引
|
||||||
end
|
end
|
||||||
|
|
||||||
### 快速排序(尾遞迴最佳化)
|
### 快速排序(尾遞迴最佳化)###
|
||||||
def quick_sort(nums, left, right)
|
def quick_sort(nums, left, right)
|
||||||
# 子陣列長度不為 1 時遞迴
|
# 子陣列長度不為 1 時遞迴
|
||||||
while left < right
|
while left < right
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user