Skip to content

Commit 819438c

Browse files
Update implementation-based.md
1 parent 2d145c9 commit 819438c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

‎implementation-based.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff 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/)

0 commit comments

Comments
(0)