I am trying to implement a BST library for teaching purposes, and I am a bit stuck. First of all, I am trying to implement the ‘insert’ operation as a ‘persistent’ one; i.e., by rebuilding the path to the newly inserted node.
Given this setup, what would be the best way to handle “parent” nodes without making the code very hairy?
I feel I am missing something either obvious or too subtle (or technically sophisticate).
This is doable, provided you are doing insert only and not rebalancing. But if you delete or change a parent, the entire tree would need to be rebuilt. Or you use setarg to modify the terms.
See section 9.3 “Insertion and deletion in binary dictionary” of Ivan Bratko’s Prolog Programming for Artificial Intelligence (I have an old edition - 1986 Addison-Wesley - so the chapters might have changed).