This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Red Black Tree”. 1. What is the special property of red-black trees and what root should always be? a) a color which is either red or black and root should always be black color only b) height of the tree c) pointer to next node d) a color which is either green or black View Answer Answer: a 2. Why do we impose restrictions like . root property is black . every leaf is black . children of red node are black . all leaves have same black a) to get logarithm time complexity b) to get linear time complexity c) to get exponential time complexity d) to get constant time complexity View Answer Answer: a Explanation: We impose such restrictions to achieve self balancing trees with logarithmic complexities for insertions, deletions, search. 3. Cosider the below formations of red-black tree. View Answer Answer: a
Subscribe Now: Data Structure Newsletter | Important Subjects Newsletters 4. What are the operations that could be performed in O(logn) time complexity by red-black tree? a) insertion, deletion, finding predecessor, successor b) only insertion c) only finding predecessor, successor d) for sorting View Answer Answer: a Explanation: We impose restrictions to achieve logarithm time complexities. impose restrictions are: . root property is black . every leaf is black . children of red node are black . all leaves have same black. 5. Which of the following is an application of Red-black trees and why? a) used to store strings efficiently b) used to store integers efficiently c) can be used in process schedulers, maps, sets d) for efficient sorting View Answer Answer: c
Participate in Data Structure I Certification Contest of the Month Now! 6. When it would be optimal to prefer Red-black trees over AVL trees? a) when there are more insertions or deletions b) when more search is needed c) when tree must be balanced d) when log(nodes) time complexity is needed View Answer Answer: a 7. Why Red-black trees are preferred over hash tables though hash tables have constant time complexity? a) no they are not preferred b) because of resizing issues of hash table and better ordering in redblack trees c) because they can be implemented using trees d) because they are balanced View Answer Answer: b 8. How can you save memory when storing color information in Red-Black tree? a) using least significant bit of one of the pointers in the node for color information b) using another array with colors of each node c) storing color information in the node structure d) using negative and positive numbering View Answer Answer: a 9. When to choose Red-Black tree, AVL tree and B-trees? a) many inserts, many searches and when managing more items respectively b) many searches, when managing more items respectively and many inserts respectively c) sorting, sorting and retrieval respectively d) retrieval, sorting and retrieval respectively View Answer Answer: a 10. What is the below pseudo code trying to do, where pt is a node pointer and root pointer? redblack(Node root, Node pt) : if (root == NULL) return pt if (pt.data < root.data) { root.left = redblack(root.left, pt); root.left.parent = root } else if (pt.data > root.data) { root.right = redblackt(root.right, pt) root.right.parent = root } return root a) insert a new node b) delete a node c) search a node d) count the number of nodes View Answer Answer: a Sanfoundry Global Education & Learning Series – Data Structure. To practice all areas of Data Structure, here is complete set of 1000+ Multiple Choice Questions and Answers. Next Steps:
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn. Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses. |