From b884d385e302a7683242ee211f201c616f0ea0ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Estev=C3=A3o=20Goerll?= <90577512+goerll@users.noreply.github.com> Date: Fri, 26 Jul 2024 05:48:35 -0300 Subject: [PATCH 1/2] fix: right-left and left-right inversion for the English version of AVL Tree (#1448) * Fix right-left and left-right inversion on AVL Binary Tree * Update avl_tree.md * Update avl_tree.md --------- Co-authored-by: Yudong Jin --- en/docs/chapter_tree/avl_tree.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/en/docs/chapter_tree/avl_tree.md b/en/docs/chapter_tree/avl_tree.md index 70f159812..68bd5e088 100644 --- a/en/docs/chapter_tree/avl_tree.md +++ b/en/docs/chapter_tree/avl_tree.md @@ -289,17 +289,17 @@ It can be observed that **the right and left rotation operations are logically s [file]{avl_tree}-[class]{avl_tree}-[func]{left_rotate} ``` -### Right-left rotation +### Left-right rotation For the unbalanced node 3 shown in the figure below, using either left or right rotation alone cannot restore balance to the subtree. In this case, a "left rotation" needs to be performed on `child` first, followed by a "right rotation" on `node`. -![Right-left rotation](avl_tree.assets/avltree_left_right_rotate.png) +![Left-right rotation](avl_tree.assets/avltree_left_right_rotate.png) -### Left-right rotation +### Right-left rotation As shown in the figure below, for the mirror case of the above unbalanced binary tree, a "right rotation" needs to be performed on `child` first, followed by a "left rotation" on `node`. -![Left-right rotation](avl_tree.assets/avltree_right_left_rotate.png) +![Right-left rotation](avl_tree.assets/avltree_right_left_rotate.png) ### Choice of rotation From 89a911583da4db60a59f49ccdb80bf7686650262 Mon Sep 17 00:00:00 2001 From: Yuelin Xin Date: Fri, 26 Jul 2024 16:50:22 +0800 Subject: [PATCH 2/2] translation: refine translation of chapter_heap/summary.md (#1383) * refine translation of heap/summary.md * Update summary.md * Update summary.md --- en/docs/chapter_heap/summary.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/en/docs/chapter_heap/summary.md b/en/docs/chapter_heap/summary.md index 03ae24af1..83b126f5f 100644 --- a/en/docs/chapter_heap/summary.md +++ b/en/docs/chapter_heap/summary.md @@ -2,16 +2,16 @@ ### Key review -- A heap is a complete binary tree, which can be divided into a max heap and a min heap based on its property. The top element of a max (min) heap is the largest (smallest). +- A heap is a complete binary tree that can be categorized as either a max heap or a min heap based on its building property, where the top element of a max heap is the largest and the top element of a min heap is the smallest. - A priority queue is defined as a queue with dequeue priority, usually implemented using a heap. - Common operations of a heap and their corresponding time complexities include: element insertion into the heap $O(\log n)$, removing the top element from the heap $O(\log n)$, and accessing the top element of the heap $O(1)$. - A complete binary tree is well-suited to be represented by an array, thus heaps are commonly stored using arrays. - Heapify operations are used to maintain the properties of the heap and are used in both heap insertion and removal operations. -- The time complexity of inserting $n$ elements into a heap and building the heap can be optimized to $O(n)$, which is highly efficient. +- The time complexity of building a heap given an input of $n$ elements can be optimized to $O(n)$, which is highly efficient. - Top-k is a classic algorithm problem that can be efficiently solved using the heap data structure, with a time complexity of $O(n \log k)$. ### Q & A **Q**: Is the "heap" in data structures the same concept as the "heap" in memory management? -The two are not the same concept, even though they are both referred to as "heap". The heap in computer system memory is part of dynamic memory allocation, where the program can use it to store data during execution. The program can request a certain amount of heap memory to store complex structures like objects and arrays. When these data are no longer needed, the program needs to release this memory to prevent memory leaks. Compared to stack memory, the management and usage of heap memory need to be more cautious, as improper use may lead to memory leaks and dangling pointers. +The two are not the same concept, even though they are both referred to as "heap". The heap in computer system memory is part of dynamic memory allocation, where the program can use it to store data during execution. The program can request a certain amount of heap memory to store complex structures like objects and arrays. When the allocated data is no longer needed, the program needs to release this memory to prevent memory leaks. Compared to stack memory, the management and usage of heap memory demands more caution, as improper use may lead to memory leaks and dangling pointers.