E1-E4 Quizzes

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

B. binary search tree definition

21.1 A __________ (with no duplicate elements) has the property that for every node in the tree the value of any node in its left subtree is less than the value of the node and the value of any node in its right subtree is greater than the value of the node.

A. inorder traversal

21.3 The ________ is to visit the left subtree of the current node first, then the current node itself, and finally the right subtree of the current node.

C. postorder traversal

21.4 The _________ is to visit the left subtree of the current node first, then the right subtree of the current node, and finally the current node itself.

B. preorder traversal

21.5 The _________ is to visit the current node first, then the left subtree of the current node, and finally the right subtree of the current node.

D. breadth-first traversal

21.6 The _________ is to visit the nodes level by level. First visit the root, then all children of the root from left to right, then grandchildren of the root from left to right, and so on.

How many distinct BSTs can be constructed with n distinct keys?

2nCn/(n+1) = 6C3/4 = 5

21.7 If a set of the same elements is inserted into a binary tree in two different orders, which of the following statements are true?

B. The inorder traversal generate the same sequence of nodes.

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

d) In order sequence gives decreasing order of elements

10. What are the conditions for an optimal binary search tree and what is its advantage?

Explanation: For an optimal binary search The tree should not be modified and we need to find how often keys are accessed. Optimal binary search improves the lookup cost.

In delete operation of BST, we need inorder successor (or predecessor) of a node when the node to be deleted has both left and right child as non-empty. Which of the following is true about inorder successor needed in delete operation?

Inorder successor is always either a leaf node or a node with empty left child. Let X be the node to be deleted in a tree with root as 'root'. There are three cases for deletion 1) X is a leaf node: We change left or right pointer of parent to NULL (depending upon whether X is left or right child of its parent) and we delete X 2) One child of X is empty: We copy values of non-empty child to X and delete the non-empty child 3) Both children of X are non-empty: In this case, we find inorder successor of X. Let the inorder successor be Y. We copy the contents of Y to X, and delete Y. Sp we need inorder successor only when both left and right child of X are not empty. In this case, the inorder successor Y can never be an ancestor of X. In this case, the inorder successor is the leftmost node in right subtree of X. Since it is leftmost node, the left child of Y must be empty.

21.2 In the implementation of BinaryTree, which of the following are true?

Node has a property named left that links to the left subtree and a property named right that links to the right subtree. BinaryTree contains a property named root. If tree is empty, root is null.

We are given a set of n distinct elements and an unlabeled binary tree with n nodes. In how many ways can we populate the tree with the given set so that it becomes a binary search tree? (GATE CS 2011)

There is only one way. The minimum value has to go to the leftmost node and the maximum value to the rightmost node. Recursively, we can define for other nodes.

Which of the following traversals is sufficient to construct BST from given traversals 1) Inorder 2) Preorder 3) Postorder

When we know either preorder or postorder traversal, we can construct the BST

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

b) It traverses in an increasing order

8. What are the worst case and average case complexities of a binary search tree?

d) O(n), O(logn) Explanation: Worst case arises when the tree is skewed(either to the left or right) in which case you have to process all the nodes of the tree giving O(n) complexity, otherwise O(logn) as you process only the left half or the right half of the tree.


Kaugnay na mga set ng pag-aaral

2204 Issues Related to Human Sexuality and Gender Identity, Chapter 20 Sexual Dysfunctions, Gender Dysphoria, and Paraphilias, Chapter 27 - Sexual Disorder & Gender Identity

View Set

(6) BUSN Chapter 6- Organization Design & Structure

View Set

Stocks vs. Bonds, Financial Literacy

View Set

CHAPTER 49: DRUG THERAPY WITH OPIOIDS

View Set