Bug fixes and improvements (#1380)

* preorder, inorder, postorder -> pre-order, in-order, post-order

* Bug fixes

* Bug fixes

* Update what_is_dsa.md

* Sync zh and zh-hant versions

* Sync zh and zh-hant versions.

* Update performance_evaluation.md and time_complexity.md

* Add @khoaxuantu to the landing page.

* Sync zh and zh-hant versions

* Add @ khoaxuantu to the landing page of zh-hant and en versions.
This commit is contained in:
Yudong Jin
2024-05-31 16:39:06 +08:00
committed by GitHub
parent 39a6890b7e
commit 3f4220de81
91 changed files with 1709 additions and 181 deletions

View File

@ -122,17 +122,17 @@
Queue<Integer> minHeap = new PriorityQueue<>();
// 初始化大頂堆積(使用 lambda 表示式修改 Comparator 即可)
Queue<Integer> maxHeap = new PriorityQueue<>((a, b) -> b - a);
/* 元素入堆積 */
maxHeap.offer(1);
maxHeap.offer(3);
maxHeap.offer(2);
maxHeap.offer(5);
maxHeap.offer(4);
/* 獲取堆積頂元素 */
int peek = maxHeap.peek(); // 5
/* 堆積頂元素出堆積 */
// 出堆積元素會形成一個從大到小的序列
peek = maxHeap.poll(); // 5
@ -140,13 +140,13 @@
peek = maxHeap.poll(); // 3
peek = maxHeap.poll(); // 2
peek = maxHeap.poll(); // 1
/* 獲取堆積大小 */
int size = maxHeap.size();
/* 判斷堆積是否為空 */
boolean isEmpty = maxHeap.isEmpty();
/* 輸入串列並建堆積 */
minHeap = new PriorityQueue<>(Arrays.asList(1, 3, 2, 5, 4));
```
@ -337,7 +337,7 @@
max_heap.push(2);
max_heap.push(5);
max_heap.push(4);
/* 獲取堆積頂元素 */
let peek = max_heap.peek().unwrap(); // 5
@ -373,17 +373,17 @@
var minHeap = PriorityQueue<Int>()
// 初始化大頂堆積(使用 lambda 表示式修改 Comparator 即可)
val maxHeap = PriorityQueue { a: Int, b: Int -> b - a }
/* 元素入堆積 */
maxHeap.offer(1)
maxHeap.offer(3)
maxHeap.offer(2)
maxHeap.offer(5)
maxHeap.offer(4)
/* 獲取堆積頂元素 */
var peek = maxHeap.peek() // 5
/* 堆積頂元素出堆積 */
// 出堆積元素會形成一個從大到小的序列
peek = maxHeap.poll() // 5
@ -391,13 +391,13 @@
peek = maxHeap.poll() // 3
peek = maxHeap.poll() // 2
peek = maxHeap.poll() // 1
/* 獲取堆積大小 */
val size = maxHeap.size
/* 判斷堆積是否為空 */
val isEmpty = maxHeap.isEmpty()
/* 輸入串列並建堆積 */
minHeap = PriorityQueue(mutableListOf(1, 3, 2, 5, 4))
```
@ -405,7 +405,7 @@
=== "Ruby"
```ruby title="heap.rb"
# Ruby 未提供內建 Heap 類別
```
=== "Zig"
@ -533,6 +533,6 @@
## 堆積的常見應用
- **優先佇列**:堆積通常作為實現優先佇列的首選資料結構,其入列和出列操作的時間複雜度均為 $O(\log n)$ ,而建操作為 $O(n)$ ,這些操作都非常高效。
- **優先佇列**:堆積通常作為實現優先佇列的首選資料結構,其入列和出列操作的時間複雜度均為 $O(\log n)$ ,而建堆積操作為 $O(n)$ ,這些操作都非常高效。
- **堆積排序**:給定一組資料,我們可以用它們建立一個堆積,然後不斷地執行元素出堆積操作,從而得到有序資料。然而,我們通常會使用一種更優雅的方式實現堆積排序,詳見“堆積排序”章節。
- **獲取最大的 $k$ 個元素**:這是一個經典的演算法問題,同時也是一種典型應用,例如選擇熱度前 10 的新聞作為微博熱搜,選取銷量前 10 的商品等。