Data Structures Trees Question:

Download Job Interview Questions and Answers PDF

Can you explain implementation of deletion from a binary tree?

Data Structures Trees Interview Question
Data Structures Trees Interview Question

Answer:

To implement the deletion from a binary tree, there is a need to consider the possibilities of deleting the nodes. They are:

- Node is a terminal node: In case the node is the left child node of its parent, then the left pointer of its parent is set to NULL. In all other cases, if the node is right child node of its parent, then the right pointer of its parent is set to NULL.

- Node has only one child: In this scenario, the appropriate pointer of its parent is set to child node.

- Node has two children: The predecessor is replaced by the node value, and then the predecessor of the node is deleted.

Download Data Structures Trees Interview Questions And Answers PDF

Previous QuestionNext Question
Do you know implementation of traversal of a binary tree?Explain Trees using C++ with an example?