This commit is contained in:
krahets
2023-12-28 17:18:44 +08:00
parent 5e0d7327db
commit b8a5bd790b
114 changed files with 860 additions and 863 deletions
+3 -3
View File
@@ -1719,7 +1719,7 @@
<span class="md-ellipsis">
8.3 &nbsp; Top-K 问题
8.3 &nbsp; Top-k 问题
</span>
@@ -3825,8 +3825,8 @@
</div>
</div>
</div>
<p><strong>时间复杂度 <span class="arithmatex">\(O(\log n)\)</span></strong> :在二分循环中,区间每轮缩小一半,循环次数为 <span class="arithmatex">\(\log_2 n\)</span></p>
<p><strong>空间复杂度 <span class="arithmatex">\(O(1)\)</span></strong> :指针 <span class="arithmatex">\(i\)</span><span class="arithmatex">\(j\)</span> 使用常数大小空间。</p>
<p><strong>时间复杂度 <span class="arithmatex">\(O(\log n)\)</span></strong> :在二分循环中,区间每轮缩小一半,循环次数为 <span class="arithmatex">\(\log_2 n\)</span></p>
<p><strong>空间复杂度 <span class="arithmatex">\(O(1)\)</span></strong> :指针 <span class="arithmatex">\(i\)</span><span class="arithmatex">\(j\)</span> 使用常数大小空间。</p>
<h2 id="1011">10.1.1 &nbsp; 区间表示方法<a class="headerlink" href="#1011" title="Permanent link">&para;</a></h2>
<p>除了上述双闭区间外,常见的区间表示还有“左闭右开”区间,定义为 <span class="arithmatex">\([0, n)\)</span> ,即左边界包含自身,右边界不包含自身。在该表示下,区间 <span class="arithmatex">\([i, j)\)</span><span class="arithmatex">\(i = j\)</span> 时为空。</p>
<p>我们可以基于该表示实现具有相同功能的二分查找算法:</p>
@@ -1719,7 +1719,7 @@
<span class="md-ellipsis">
8.3 &nbsp; Top-K 问题
8.3 &nbsp; Top-k 问题
</span>
@@ -3940,7 +3940,7 @@
<p>代码在此省略,以下两点值得注意。</p>
<ul>
<li>给定数组不包含小数,这意味着我们无须关心如何处理相等的情况。</li>
<li>因为该方法引入了小数,所以需要将函数中的变量 <code>target</code> 改为浮点数类型。</li>
<li>因为该方法引入了小数,所以需要将函数中的变量 <code>target</code> 改为浮点数类型Python 无须改动)</li>
</ul>
<!-- Source file information -->
@@ -1719,7 +1719,7 @@
<span class="md-ellipsis">
8.3 &nbsp; Top-K 问题
8.3 &nbsp; Top-k 问题
</span>
@@ -3519,7 +3519,7 @@
<h2 id="1021">10.2.1 &nbsp; 无重复元素的情况<a class="headerlink" href="#1021" title="Permanent link">&para;</a></h2>
<div class="admonition question">
<p class="admonition-title">Question</p>
<p>给定一个长度为 <span class="arithmatex">\(n\)</span> 的有序数组 <code>nums</code> 和一个元素 <code>target</code> ,数组不存在重复元素。现将 <code>target</code> 插入数组 <code>nums</code> 中,并保持其有序性。若数组中已存在元素 <code>target</code> ,则插入到其左方。请返回插入后 <code>target</code> 在数组中的索引。</p>
<p>给定一个长度为 <span class="arithmatex">\(n\)</span> 的有序数组 <code>nums</code> 和一个元素 <code>target</code> ,数组不存在重复元素。现将 <code>target</code> 插入数组 <code>nums</code> 中,并保持其有序性。若数组中已存在元素 <code>target</code> ,则插入到其左方。请返回插入后 <code>target</code> 在数组中的索引。示例如图 10-4 所示。</p>
</div>
<p><a class="glightbox" href="../binary_search_insertion.assets/binary_search_insertion_example.png" data-type="image" data-width="100%" data-height="auto" data-desc-position="bottom"><img alt="二分查找插入点示例数据" class="animation-figure" src="../binary_search_insertion.assets/binary_search_insertion_example.png" /></a></p>
<p align="center"> 图 10-4 &nbsp; 二分查找插入点示例数据 </p>
+1 -1
View File
@@ -1719,7 +1719,7 @@
<span class="md-ellipsis">
8.3 &nbsp; Top-K 问题
8.3 &nbsp; Top-k 问题
</span>
@@ -1719,7 +1719,7 @@
<span class="md-ellipsis">
8.3 &nbsp; Top-K 问题
8.3 &nbsp; Top-k 问题
</span>
@@ -1719,7 +1719,7 @@
<span class="md-ellipsis">
8.3 &nbsp; Top-K 问题
8.3 &nbsp; Top-k 问题
</span>
@@ -3651,7 +3651,7 @@
<li>适用于海量数据,因为树节点在内存中是分散存储的。</li>
<li>适合需要维护有序数据或范围查找的场景。</li>
<li>在持续增删节点的过程中,二叉搜索树可能产生倾斜,时间复杂度劣化至 <span class="arithmatex">\(O(n)\)</span></li>
<li>若使用 AVL 树或红黑树,则各项操作可在 <span class="arithmatex">\(O(\log n)\)</span> 效率下稳定运行,但维护树平衡的操作会增加额外开销。</li>
<li>若使用 AVL 树或红黑树,则各项操作可在 <span class="arithmatex">\(O(\log n)\)</span> 效率下稳定运行,但维护树平衡的操作会增加额外开销。</li>
</ul>
<!-- Source file information -->
+1 -1
View File
@@ -1719,7 +1719,7 @@
<span class="md-ellipsis">
8.3 &nbsp; Top-K 问题
8.3 &nbsp; Top-k 问题
</span>