You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert

3
+
[]()[]()[]()[]()
This essay records the course of and my emotion to this project from initialization to 10,000 stars.
19
-
[Milestone for 10,000+ stars](./thanksGiving.md)
13
+
This essay records the course of and my emotion to this project from initialization to 10,000 stars. [Milestone for 10,000+ stars](./thanksGiving.md)
20
14
21
15
If you are interested in this project, **do not mean your star**. This project will be **supported for a long enough time** by the community. Thanks for every audience and contributor.
22
16
@@ -96,7 +90,7 @@ The data structures mainly include:
96
90
97
91
> Here only lists some **representative problems** but not all.
Copy file name to clipboardExpand all lines: thinkings/balanced-tree.en.md
+6-11
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Balanced Binary Tree Topic
1
+
# Balanced Binary Tree
2
2
3
3
There are still some topics related to balancing binary trees, and they are all very classic. It is recommended that everyone practice. Today, I have selected 4 questions for everyone. If you thoroughly understand these questions, you should not be out of ideas when you encounter other balanced binary tree questions. After you understand my thoughts, it is recommended to find a few more topics to practice your hands and consolidate your learning results.
- Time complexity: for isBalanced to say, since each node has at most be accessed once, this part of the time complexity is $O(N)$, while the dfs function each time it is call the number of not more than $log N$, so the total time complexity is $O(NlogN)$, where $N$ is a tree of nodes total.
90
-
-Spatial complexity: Due to the use of recursion, the bottleneck of spatial complexity here is in the stack space, so the spatial complexity is $O(h)$, where $H$ is the height of the tree.
89
+
- Time complexity: for isBalanced to say, since each node has at most be accessed once, this part of the time complexity is $O(N)$, while the dfs function each time it is call the number of not more than $log N$, so the total time complexity is $O(NlogN)$, where $N$ is a tree of nodes total. -Spatial complexity: Due to the use of recursion, the bottleneck of spatial complexity here is in the stack space, so the spatial complexity is $O(h)$, where $H$ is the height of the tree.
91
90
92
91
## 108. Convert an ordered array to a binary search tree (simple)
93
92
@@ -148,8 +147,7 @@ return root
148
147
149
148
**Complexity analysis**
150
149
151
-
-Time complexity: Since each node is accessed at most once, the total time complexity is $O(N)$, where $N$ is the length of the array.
152
-
-Spatial complexity: Due to the use of recursion, the bottleneck of spatial complexity here is in the stack space, so the spatial complexity is $O(h)$, where $H$ is the height of the tree. At the same time, because it is a balanced binary tree, $h$ is 就是 log N$.
150
+
-Time complexity: Since each node is accessed at most once, the total time complexity is $O(N)$, where $N$ is the length of the array. -Spatial complexity: Due to the use of recursion, the bottleneck of spatial complexity here is in the stack space, so the spatial complexity is $O(h)$, where $H$ is the height of the tree. At the same time, because it is a balanced binary tree, $h$ is 就是 log N$.
153
151
154
152
## 109. Ordered linked list conversion binary search tree (medium)
155
153
@@ -184,8 +182,7 @@ The same idea as 108. The difference is the different data structures, so we nee
 (The case of the linked list)
189
186
190
187
To find the midpoint, you only need to use the classic speed pointer. At the same time, in order to prevent the ring from appearing, we need to cut off the next pointer to mid, so we need to record a node before the midpoint. This only needs to be recorded with a variable pre.
191
188
@@ -296,8 +293,7 @@ return root;
296
293
297
294
Let n be the length of the linked list.
298
295
299
-
- Time complexity: the recursion tree of depth $logn$, each layer of the basic operation of the number of $n$, so the total time complexity is$O(nlogn)$
300
-
-Spatial complexity: The spatial complexity is$O(logn)$
296
+
- Time complexity: the recursion tree of depth $logn$, each layer of the basic operation of the number of $n$, so the total time complexity is$O(nlogn)$ -Spatial complexity: The spatial complexity is$O(logn)$
301
297
302
298
Some students are not very good at analyzing the time complexity and space complexity of recursion. We will introduce it to you again here.
303
299
@@ -309,8 +305,7 @@ The time complexity is a little bit more difficult. Before, Sifa told everyone i
309
305
310
306
However, we found that the basic operands of each layer of the recursive tree are fixed, and the number of fixed operations has been calculated for everyone on the graph. Therefore, the total spatial complexity can actually be calculated by the \*\* recursion depth\* The basic operands of each layer, which is $nlogn$. Similar techniques can be used in the complexity analysis of merge sorting.
311
307
312
-
In addition, everyone can directly derive it from the formula. For this question, set the basic operand T(n), then there is T(n)= T(n/2)\*2+ n/2, and it is deduced that T(n) is probably nlogn. This should be high school knowledge.
313
-
The specific derivation process is as follows:
308
+
In addition, everyone can directly derive it from the formula. For this question, set the basic operand T(n), then there is T(n)= T(n/2)\*2+ n/2, and it is deduced that T(n) is probably nlogn. This should be high school knowledge. The specific derivation process is as follows:
0 commit comments