## How do you delete a node from a binary search tree?

Delete function is used to delete the specified node from a binary search tree….Function:

- void deletion(Node*& root, int item)
- {
- Node* parent = NULL;
- Node* cur = root;
- search(cur, item, parent);
- if (cur == NULL)
- return;
- if (cur->left == NULL && cur->right == NULL)

## How is a binary search tree constructed?

Construct a Binary Search Tree

- Set the current node to be the root node of the tree.
- If the target value equals the key value for the current node, then the target value is found.
- If the target value is less than the key value for a node, make the current node the left child.

**How do you add and remove an element from a binary search tree?**

Method-01:

- Visit to the right subtree of the deleting node.
- Pluck the least value element called as inorder successor.
- Replace the deleting element with its inorder successor.

### How do I remove a root node from AVL tree?

Solution: in this case, node B has balance factor -1. Deleting the node 60, disturbs the balance factor of the node 50 therefore, it needs to be R-1 rotated. The node C i.e. 45 becomes the root of the tree with the node B(40) and A(50) as its left and right child.

### What are the rules to construct expression tree?

How to construct an expression tree?

- If we get an operand in the given expression, then push it in the stack.
- If an operator gets two values in the expression, then add in the expression tree as its child, and push them in the current node.
- Repeat Step-1 and Step-2 until we do not complete over the given expression.

**What is a binary search tree How can you insert and delete an element in a BST explain using suitable examples?**

Basic operations on a BST

- Create: creates an empty tree.
- Insert: insert a node in the tree.
- Search: Searches for a node in the tree.
- Delete: deletes a node from the tree.
- Inorder: in-order traversal of the tree.
- Preorder: pre-order traversal of the tree.
- Postorder: post-order traversal of the tree.

#### How do insertions and deletions differ in a BST?

Insertion: For inserting element as left child of 2, we have to traverse all elements. Therefore, insertion in binary tree has worst case complexity of O(n). Deletion: For deletion of element 2, we have to traverse all elements to find 2 (assuming we do breadth first traversal).