MCQOPTIONS
Saved Bookmarks
This section includes 721 Mcqs, each offering curated multiple-choice questions to sharpen your Technical Programming knowledge and support exam preparation. Choose a topic below to get started.
| 451. |
What does the below definations convey? i. A binary tree is balanced if for every node it is gonna hold that the number of inner nodes in the left subtree and the number of inner nodes in the right subtree differ by at most 1. ii. A binary tree is balanced if for any two leaves the difference of the depth is at most 1. |
| A. | weight balanced and height balanced tree definations |
| B. | height balanced and weight balanced tree definations |
| C. | definations of weight balanced tree |
| D. | definations of height balanced tree |
| Answer» B. height balanced and weight balanced tree definations | |
| 452. |
Why the below pseudo code where x is a value, wt is weight factor and t is root node can’t insert? WeightBalanceTreeNode insert(int x, int wt, WeightBalanceTreeNode k) : if (k == null) k = new WeightBalanceTreeNode(x, wt, null, null) else if (x < t.element) : k.left = insert (x, wt, k.left) if (k.left.weight < k.weight) k = rotateWithRightChild (k) else if (x > t.element) : k.right = insert (x, wt, k.right) if (k.right.weight < k.weight) k = rotateWithLeftChild (k) |
| A. | when x>t. element Rotate-with-left-child should take place and vice versa |
| B. | the logic is incorrect |
| C. | the condition for rotating children is wrong |
| D. | insertion cannot be performed in weight balanced trees |
| Answer» B. the logic is incorrect | |
| 453. |
Consider a weight balanced tree such that, the number of nodes in the left sub tree is at least half and at most twice the number of nodes in the right sub tree. The maximum possible height (number of nodes on the path from the root to the farthest leaf) of such a tree on k nodes can be described as |
| A. | log2 n |
| B. | log4/3 n |
| C. | log3 n |
| D. | log3/2 n |
| Answer» E. | |
| 454. |
What are the operations that can be performed on weight balanced tree? |
| A. | all basic operations and set intersection, set union and subset test |
| B. | all basic operations |
| C. | set intersection, set union and subset test |
| D. | only insertion and deletion |
| Answer» B. all basic operations | |
| 455. |
What is the condition for a tree to be weight balanced. where a is factor and n is a node? |
| A. | weight[n.left] >= a*weight[n] and weight[n.right] >= a*weight[n]. |
| B. | weight[n.left] >= a*weight[n.right] and weight[n.right] >= a*weight[n]. |
| C. | weight[n.left] >= a*weight[n.left] and weight[n.right] >= a*weight[n]. |
| D. | weight[n] is a non zero |
| Answer» B. weight[n.left] >= a*weight[n.right] and weight[n.right] >= a*weight[n]. | |
| 456. |
A node of the weight balanced tree has |
| A. | key, left and right pointers, size |
| B. | key, value |
| C. | key, size |
| D. | key |
| Answer» B. key, value | |
| 457. |
What are the applications of weight balanced tree? |
| A. | dynamic sets, dictionaries, sequences, maps |
| B. | heaps |
| C. | sorting |
| D. | storing strings |
| Answer» B. heaps | |
| 458. |
What is a weight balanced tree? |
| A. | A binary tree that stores the sizes of subtrees in nodes |
| B. | A binary tree with an additional attribute of weight |
| C. | A height balanced binary tree |
| D. | A normal binary tree |
| Answer» B. A binary tree with an additional attribute of weight | |
| 459. |
How to achieve the above operation efficiently? |
| A. | use linked lists |
| B. | use avl trees |
| C. | use red-black trees |
| D. | use treaps (cartesian trees) |
| Answer» E. | |
| 460. |
A treap is a cartesian tree with |
| A. | additional value, which is a priority value to the key generated randomly |
| B. | additional value, which is a priority value to the key generated sequentially |
| C. | additional heap rule |
| D. | additional operations like remove a range of elements |
| Answer» B. additional value, which is a priority value to the key generated sequentially | |
| 461. |
Cartesian trees are most suitable for? |
| A. | searching |
| B. | finding nth element |
| C. | minimum range query and lowest common ancestors |
| D. | self balancing a tree |
| Answer» D. self balancing a tree | |
| 462. |
After applying the below operations on a input sequence, what happens? i. construct a cartesian tree for input sequence ii. put the root element of above tree in a priority queue iii. if( priority queue is not empty) then .search and delete minimum value in priority queue .add that to output .add cartesian tree children of above node to priority queue |
| A. | constructs a cartesian tree |
| B. | sorts the input sequence |
| C. | does nothing |
| D. | produces some random output |
| Answer» C. does nothing | |
| 463. |
Consider a sequence of numbers to have repetitions, how a cartesian tree can be constructed in such situations without violating any rules? |
| A. | use any tie-breaking rule between repeated elements |
| B. | cartesian tree is impossible when repetitions are present |
| C. | construct a max heap in such cases |
| D. | construct a min heap in such cases |
| Answer» B. cartesian tree is impossible when repetitions are present | |
| 464. |
What is the speciality of cartesian sorting? |
| A. | it sorts partially sorted set of data quickly |
| B. | it considers cartesian product of elements |
| C. | it sorts elements in less than O(logn) |
| D. | it is a self balancing tree |
| Answer» B. it considers cartesian product of elements | |
| 465. |
Which of the below statements are true i.Cartesian tree is not a height balanced tree ii.Cartesian tree of a sequence of unique numbers can be unique generated |
| A. | both statements are true |
| B. | only i. is true |
| C. | only ii. is true |
| D. | both are untrue |
| Answer» B. only i. is true | |
| 466. |
What is a Cartesian tree? |
| A. | a skip list in the form of tree |
| B. | a tree which obeys cartesian product |
| C. | a tree which obeys heap property and whose inorder traversal yields the given sequence |
| D. | a tree which obeys heap property only |
| Answer» D. a tree which obeys heap property only | |
| 467. |
Why to prefer red-black trees over AVL trees? |
| A. | Because red-black is more rigidly balanced |
| B. | AVL tree store balance factor in every node which costs space |
| C. | AVL tree fails at scale |
| D. | Red black is more efficient |
| Answer» C. AVL tree fails at scale | |
| 468. |
Consider the below left-left rotation pseudo code where the node contains value pointers to left, right child nodes and a height value and Height() function returns height value stored at a particular node. avltree leftrotation(avltreenode z): avltreenode w =x-left x-left=w-right w-right=x x-height=max(Height(x-left),Height(x-right))+1 w-height=max(missing)+1 return w What is missing? |
| A. | Height(w-left), x-height |
| B. | Height(w-right), x-height |
| C. | Height(w-left), x |
| D. | Height(w-left) |
| Answer» B. Height(w-right), x-height | |
| 469. |
What maximum difference in heights between the leafs of a AVL tree is possible? |
| A. | log(n) where n is the number of nodes |
| B. | n where n is the number of nodes |
| C. | 0 or 1 |
| D. | atmost 1 |
| Answer» B. n where n is the number of nodes | |
| 470. |
Given an empty AVL tree, how would you construct AVL tree when a set of numbers are given without performing any rotations? |
| A. | just build the tree with the given input |
| B. | find the median of the set of elements given, make it as root and construct the tree |
| C. | use trial and error |
| D. | use dynamic programming to build the tree |
| Answer» C. use trial and error | |
| 471. |
What is the maximum height of an AVL tree with p nodes? |
| A. | p |
| B. | log(p) |
| C. | log(p)/2 |
| D. | p⁄2 |
| Answer» C. log(p)/2 | |
| 472. |
What is an AVL tree? |
| A. | a tree which is balanced and is a height balanced tree |
| B. | a tree which is unbalanced and is a height balanced tree |
| C. | a tree with three children |
| D. | a tree with atmost 3 children |
| Answer» B. a tree which is unbalanced and is a height balanced tree | |
| 473. |
What are the conditions for an optimal binary search tree and what is its advantage? |
| A. | The tree should not be modified and you should know how often the keys are accessed, it improves the lookup cost |
| B. | You should know the frequency of access of the keys, improves the lookup time |
| C. | The tree can be modified and you should know the number of elements in the tree before hand, it improves the deletion time |
| D. | None of the mentioned |
| Answer» B. You should know the frequency of access of the keys, improves the lookup time | |
| 474. |
What are the worst case and average case complexities of a binary search tree? |
| A. | O(n), O(n) |
| B. | O(logn), O(logn) |
| C. | O(logn), O(n) |
| D. | O(n), O(logn) |
| Answer» E. | |
| 475. |
What does the following piece of code do? public void func(Tree root) { System.out.println(root.data()); func(root.left()); func(root.right()); } |
| A. | Preorder traversal |
| B. | Inorder traversal |
| C. | Postorder traversal |
| D. | Level order traversal |
| Answer» B. Inorder traversal | |
| 476. |
What does the following piece of code do? public void func(Tree root) { func(root.left()); func(root.right()); System.out.println(root.data()); } |
| A. | Preorder traversal |
| B. | Inorder traversal |
| C. | Postorder traversal |
| D. | Level order traversal |
| Answer» D. Level order traversal | |
| 477. |
What is the speciality about the inorder traversal of a binary search tree? |
| A. | It traverses in a non increasing order |
| B. | It traverses in an increasing order |
| C. | It traverses in a random fashion |
| D. | None of the mentioned |
| Answer» C. It traverses in a random fashion | |
| 478. |
Which of the following is false about a binary search tree? |
| A. | The left child is always lesser than its parent |
| B. | The right child is always greater than its parent |
| C. | The left and right sub-trees should also be binary search trees |
| D. | None of the mentioned |
| Answer» E. | |
| 479. |
Which of the following is correct with respect to binary trees? |
| A. | Let T be a binary tree. For every k ≥ 0, there are no more than 2k nodes in level k |
| B. | Let T be a binary tree with λ levels. Then T has no more than 2λ – 1 nodes |
| C. | Let T be a binary tree with N nodes. Then the number of levels is at least ceil(log (N + 1)) |
| D. | All of the mentioned |
| Answer» E. | |
| 480. |
In a full binary tree if there are L leaves, then total number of nodes N are? |
| A. | N = 2L |
| B. | N = L + 1 |
| C. | N = L – 1 |
| D. | N = 2L – 1 |
| Answer» E. | |
| 481. |
In a full binary tree if number of internal nodes is I, then number of nodes N are? |
| A. | N = 2I |
| B. | N = I + 1 |
| C. | N = I – 1 |
| D. | N = 2I + 1 |
| Answer» E. | |
| 482. |
In a full binary tree if number of internal nodes is I, then number of leaves L are? |
| A. | L = 2I |
| B. | L = I + 1 |
| C. | L = I – 1 |
| D. | L = 2I – 1 |
| Answer» C. L = I – 1 | |
| 483. |
Which of the following is not an advantage of trees? |
| A. | Hierarchical structure |
| B. | Faster search |
| C. | Router algorithms |
| D. | Undo/Redo operations in a notepad |
| Answer» E. | |
| 484. |
What is the time complexity for finding the height of the binary tree? |
| A. | h = O(loglogn) |
| B. | h = O(nlogn) |
| C. | h = O(n) |
| D. | h = O(log n) |
| Answer» E. | |
| 485. |
What is a complete binary tree? |
| A. | Each node has exactly zero or two children |
| B. | A binary tree, which is completely filled, with the possible exception of the bottom level, which is filled from right to left |
| C. | A binary tree, which is completely filled, with the possible exception of the bottom level, which is filled from left to right |
| D. | None of the mentioned |
| Answer» D. None of the mentioned | |
| 486. |
What is a full binary tree? |
| A. | Each node has exactly zero or two children |
| B. | Each node has exactly two children |
| C. | All the leaves are at the same level |
| D. | Each node has exactly one or two children |
| Answer» B. Each node has exactly two children | |
| 487. |
The number of edges from the node to the deepest leaf is called _________ of the tree. |
| A. | Height |
| B. | Depth |
| C. | Length |
| D. | None of the mentioned |
| Answer» B. Depth | |
| 488. |
The number of edges from the root to the node is called __________ of the tree. |
| A. | Height |
| B. | Depth |
| C. | Length |
| D. | None of the mentioned |
| Answer» C. Length | |
| 489. |
In a binary search tree, which of the following traversals would print the numbers in the ascending order? |
| A. | Level-order traversal |
| B. | Pre-order traversal |
| C. | Post-order traversal |
| D. | In-order traversal |
| Answer» E. | |
| 490. |
Which of the following graph traversals closely imitates level order traversal of a binary tree? |
| A. | Depth First Search |
| B. | Breadth First Search |
| C. | Depth & Breadth First Search |
| D. | None of the mentioned |
| Answer» C. Depth & Breadth First Search | |
| 491. |
What is the time complexity of level order traversal? |
| A. | O(1) |
| B. | O(n) |
| C. | O(logn) |
| D. | O(nlogn) |
| Answer» C. O(logn) | |
| 492. |
What is the space complexity of the in-order traversal in the recursive fashion? (d is the tree depth and n is the number of nodes) |
| A. | O(1) |
| B. | O(nlogd) |
| C. | O(logd) |
| D. | O(d) |
| Answer» E. | |
| 493. |
For the tree below, write the level-order traversal. |
| A. | 2, 7, 2, 6, 5, 11, 5, 9, 4 |
| B. | 2, 7, 5, 2, 6, 9, 5, 11, 4 |
| C. | 2, 5, 11, 6, 7, 4, 9, 5, 2 |
| D. | 2, 7, 5, 6, 11, 2, 5, 4, 9 |
| Answer» C. 2, 5, 11, 6, 7, 4, 9, 5, 2 | |
| 494. |
For the tree below, write the in-order traversal. |
| A. | 2, 7, 2, 6, 5, 11, 5, 9, 4 |
| B. | 2, 7, 5, 2, 6, 9, 5, 11, 4 |
| C. | 2, 5, 11, 6, 7, 4, 9, 5, 2 |
| D. | 2, 7, 5, 6, 11, 2, 5, 4, 9 |
| Answer» E. | |
| 495. |
To obtain a prefix expression, which of the tree traversals is used? |
| A. | Level-order traversal |
| B. | Pre-order traversal |
| C. | Post-order traversal |
| D. | In-order traversal |
| Answer» C. Post-order traversal | |
| 496. |
What is the space complexity of the post-order traversal in the recursive fashion? (d is the tree depth and n is the number of nodes) |
| A. | O(1) |
| B. | O(nlogd) |
| C. | O(logd) |
| D. | O(d) |
| Answer» E. | |
| 497. |
What is the time complexity of pre-order traversal in the iterative fashion? |
| A. | O(1) |
| B. | O(n) |
| C. | O(logn) |
| D. | O(nlogn) |
| Answer» C. O(logn) | |
| 498. |
For the tree below, write the post-order traversal. |
| A. | 2, 7, 2, 6, 5, 11, 5, 9, 4 |
| B. | 2, 7, 5, 2, 6, 9, 5, 11, 4 |
| C. | 2, 5, 11, 6, 7, 4, 9, 5, 2 |
| D. | 2, 7, 5, 6, 11, 2, 5, 4, 9 |
| Answer» D. 2, 7, 5, 6, 11, 2, 5, 4, 9 | |
| 499. |
For the tree below, write the pre-order traversal. |
| A. | 2, 7, 2, 6, 5, 11, 5, 9, 4 |
| B. | 2, 7, 5, 2, 6, 9, 5, 11, 4 |
| C. | 2, 5, 11, 6, 7, 4, 9, 5, 2 |
| D. | 2, 7, 5, 6, 11, 2, 5, 4, 9 |
| Answer» B. 2, 7, 5, 2, 6, 9, 5, 11, 4 | |
| 500. |
What is the code below trying to print? void print(tree *root,tree *node) { if(root ==null) return 0 if(root-->left==node || root-->right==node || print(root->left,node)||printf(root->right,node) { print(root->data) } } |
| A. | just printing all nodes |
| B. | not a valid logic to do any task |
| C. | printing ancestors of a node passed as argument |
| D. | printing nodes from leaf node to a node passed as argument |
| Answer» D. printing nodes from leaf node to a node passed as argument | |