algorithmternary-tree

How to delete a node in Ternary Tree?


I am working on implementing a Java program on inserting and deleting a node in a ternary tree.

I am able to implement insertion without any issues, but I'm facing a few hiccups in implementing the deletion operation.

So, my question is:

How to delete a node from ternary tree if it has one or more child nodes?

It will be great if you can share any logic or pseudo-code to implement the "delete" functionality.


Solution

  • I found a solution.


    Suppose n is the node we want to delete, l is its left child, r is its right child and m is its middle child.