What's the good algorithm to keep the numbers sorted while it continually adds new numbers? Any built-in library in Python for it?
My idea is self-balanced binary searching tree
Insert: O(log(n))
Get top k numbers: O(k) do in-order travel
Get all sorted numbers: O(n) do in-order travel
Binary Heap works too but slower
Insert: O(log(n))
Get top k numbers: O(k*log(n)) pop out k numbers
Get all numbers: O(n*log(n)) pop out all
Thank you!