# What are the advantages of BST?

Table of Contents

## What are the advantages of BST?

Advantages of BST are:

- we can always keep the cost of insert(), delete(), lookup() to O(logN) where N is the number of nodes in the tree – so the benefit really is that lookups can be done in logarithmic time which matters a lot when N is large.
- We have an ordering of keys stored in the tree.
- We can impleme.

## What is level order traversal?

Trees can also be traversed in level order, where we visit every node on a level before going to a lower level. This search is referred to as level order traversal or Breadthâ€“first search (BFS), as the search tree is broadened as much as possible on each depth before going to the next depth.

## Which traversal outputs the data in sorted order in a BST?

Explanation: Inorder traversal of a BST outputs data in sorted order.

## How can you tell if a binary tree is a mirror?

Based on the symmetric definition, we can use the following rules to check whether two binary trees are a mirror reflection of each other:

- The two root nodes have the same value.
- The left subtree of one root node is a mirror reflection of the right subtree of the other root node.

## How can you tell if a tree is symmetric?

If the tree is empty, then it is symmetrical to the vertical axis going through its root node. Else, check if the value at the root node of both subtrees is the same. If it is, then check if the left subtree and the right subtree are symmetrical.

## How do you invert a binary tree?

An inversion, or mirror, of a Binary Tree (T),â€‹ is just a Binary Tree M(T) whose left and right children (of all non-leaf nodes) are swapped….The solution is a simple recursive approach:

- Call invert for left-subtree.
- Call invert for right-subtree.
- Swap left and right subtrees.

## What does it mean to invert a binary tree?

An inverted form of a Binary Tree is another Binary Tree with left and right children of all non-leaf nodes interchanged. You may also call it the mirror of the input tree. NOTE: The tree is binary so there could be a maximum of two child nodes. This problem was originally inspired by this tweet by Max Howell .

## How do you create a mirror image of a binary tree?

Algorithm to create a mirror image of a tree

- If root is NULL, return NULL.
- Create a new node and copy the data of root node to new node. Let the name if new node be newNode.
- Recursively create mirror tree of left and right sub tree. let it be leftMirror and rightMirror.
- Interchange left and right pointers.