# Is deletion commutative in binary search tree?

## Is deletion commutative in binary search tree?

No, deletion is not commutative. To see why, consider the tree with root 5, children 3 and 7, and 6 as a child of 7. We will delete 5 and 3: if 5 is deleted first, then we get the tree with root 6, children 3 and 7; after deleting 3 we get the tree with root 6 and right child 7.

## Is insertion in BST commutative?

Insertion in a binary search tree is “commutative”. That is, inserting x and then y into a binary search tree leaves the same tree as inserting y and then x. A red-black tree on 128 keys must have at least 1 red node. A heap with n elements can be converted into a binary search tree in O(n) time.

**What are the three cases to consider when deleting node N from a binary search tree as stated in the textbook )?**

There are three possible cases to consider deleting a node from BST:

- Case 1: Deleting a node with no children: remove the node from the tree.
- Case 2: Deleting a node with two children: call the node to be deleted N . Do not delete N .
- Case 3: Deleting a node with one child: remove the node and replace it with its child.

**Which of the following options is not true about the binary search tree?**

Which of the following is false about a binary search tree? Explanation: In order sequence of binary search trees will always give ascending order of elements. Remaining all are true regarding binary search trees.

### How do you add an element to a binary search tree?

Insertion

- Allocate the memory for tree.
- Set the data part to the value and set the left and right pointer of tree, point to NULL.
- If the item to be inserted, will be the first element of the tree, then the left and right of this node will point to NULL.

### How many types of deletion are performed in a binary tree?

There are three situations of deleting a node from binary search tree.

**What is the time and space complexity of deletion in a binary tree?**

Time Complexity Problems on Binary Tree

Operation | Worst Case | Best Case |
---|---|---|

Insert | O(N) | O(logN) |

Search | O(N) | O(1) |

Delete | O(N) | O(logN) |

**What is false about binary search tree?**

1. Which of the following is false about a binary search tree? Explanation: In order sequence of binary search trees will always give ascending order of elements. Remaining all are true regarding binary search trees.