For a given, tree-like data structure:
- Alan
- Barbara
- Charlie
- Cecil
- Brian
- Chris
- Candice
- Cohen
- Boromir
- Corcoran
- Arthur
- Bort
- Clive
- Chad
- Berman
- Chud
- Angel
- Barry
- Crick
All of my experience/research is around b-trees and binary trees and searching, traversing and balancing, as opposed to pruning.
Is there a known way, given a list of the leaf nodes (e.g. ["Cecil", "Candice", "Charlie", "Chad"]) to prune the tree and return only:
- Alan
- Barbara
- Charlie
- Cecil
- Brian
- Candice
- Arthur
- Bort
- Chad
prune(tree, list) -> bool
, where the return value indicates whether the tree contained one item from the list and therefore shouldn't be pruned from its parent node. For immutable data structures, the signature might look likepruned(tree, list) -> Option<Tree>