# YOU CAN DOWNLOAD 200+ SUBJECTS PDF BOOK FOR COMPETITIVE EXAMINATIONS

## Data Structure Questions and Answers-Binary Search Tree

Question 1 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER] |

Which of the following is false about a binary search tree?

The left child is always lesser than its parent | |

The right child is always greater than its parent | |

The left and right sub-trees should also be binary search trees | |

None of the mentioned |

Question 1 Explanation:

All the options hold good for a binary search tree and can be considered as a definition for a BST.

Question 2 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER] |

How to search for a key in a binary search tree?

public Tree search(Tree root, int key) { if( root == null || root.key == key ) { return root; } if( root.key < key ) { return | |

public Tree search(Tree root, int key) { if( root == null || root.key == key ) { return root; } if( root.key < key ) { return | |

public Tree search(Tree root, int key) { if( root == null) { return root; } if( root.key < key ) { return search(root.right, key | |

None of the mentioned |

Question 2 Explanation:

As we know that the left child is lesser than the parent, if the root's key is greater than the given key, we look only into the left sub-tree, similarly for right sub-tree.

Question 3 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER] |

What is the speciality about the inorder traversal of a binary search tree?

It traverses in a non increasing order | |

It traverses in an increasing order | |

It traverses in a random fashion | |

None of the mentioned |

Question 3 Explanation:

As a binary search tree consists of elements lesser than the node to the left and the ones greater than the node to the right, an inorder traversal will give the elements in an increasing order.

Question 4 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER] |

What does the following piece of code do?

public void func(Tree root) { func(root.left()); func(root.right()); System.out.println(root.data()); }

Preorder traversal | |

Inorder traversal | |

Postorder traversal | |

Level order traversal |

Question 4 Explanation:

In a postorder traversal, first the left child is visited, then the right child and finally the parent.

Question 5 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER] |

What does the following piece of code do?

public void func(Tree root) { System.out.println(root.data()); func(root.left()); func(root.right()); }

Preorder traversal | |

Inorder traversal | |

Postorder traversal | |

Level order traversal |

Question 5 Explanation:

In a preorder traversal, first the parent is visited, then the left child and finally the right child.

There are 5 questions to complete.