File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -501,6 +501,19 @@ public:
501501 return n&1 ? * st.find_by_order(n/2) : (* st.find_by_order(n/2 - 1) + * st.find_by_order(n/2))/2.0;
502502 }
503503};
504+ // Regular set uses a BST internally, red black tree uses a red black tree
505+ // Regular set has this drawback that we cannot do random access, with policy based you can even do that in O(LogN) time
506+ // order_of_key(k) number of items strictly smaller than k
507+ // find_by_order(k) kth element from set counting from zero
508+
509+ /*
510+ A BST is simply whose left node is small and right large. But often BST can end up as skewed (like a linked list)
511+ Solution is balanced trees like AVL or Red black tree which is a type of balanced tree.
512+ - A node is either black or red.
513+ - The root and nil are always black.
514+ - If a node is red its childrens are black.
515+ - All path from its nil descendants contains the same number of black nodes.
516+ * /
504517```
505518
506519### [Design HashMap](https://leetcode.com/problems/design-hashmap/)
You can’t perform that action at this time.
0 commit comments