pythonsortedcollectionsortedcontainers

Using sortedcontainers in Python to emulate BST


I see some people recommending using SortedContainers as a drop in for some tree structures like Binary Trees like this reddit thread. The documentation for SortedContainers mentions how it's more space efficient than typical implementations of Binary Trees

Having said that, I don't actually see anyone talk about HOW to use it as such and I'd greatly appreciate if someone had a reference for how to emulate a BST or something of the like using Sortedcontainers or SortedCollection


Solution

  • Update: In my use case, I didn't need to "Use sortedcontainers to emulate Tree structure X" because it IS tree structure X under the hood