Skip to content

Commit 7662c68

Browse files
committed
Comment: Big-O analysis
1 parent b5b10ee commit 7662c68

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

kth-smallest-element-in-a-bst/flynn.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
/**
22
* For the height H of the given BST,
33
*
4-
* Time complexity: O(H) at worst
4+
* Time complexity: O(max(H, K))
5+
* - if H > K, O(H) at worst
6+
* - else, O(K)
57
*
6-
* Space complexity: O(H + K) at worst
7-
* - call stack + additional vector to save nums
8+
* Space complexity: O(H > K ? H + K : K)
9+
* - additional vector to save nums O(K)
10+
* - if H > K, call stack O(H)
11+
* - else, O(K)
812
*/
913

1014
/**

0 commit comments

Comments
 (0)