Q8. Given is the following variant of member function insert of class Nodeinsert
ID: 3903729 • Letter: Q
Question
Q8. Given is the following variant of member function insert of class Nodeinsert (x) Imagine a set data structure that is rooted in a binary node N3; N3 contains value 3; node N3 has N2 (with value 2) as its left child and node N5 (with value 5) as its right child. Nodes N2 and N5 are leaves. What is the result of function call N3.insert(3)? (a) The set data structure has not changed since it already contained value 3. (b) N3 has left child N2 and right child N5, and N2 has a righ t child with value 3. (c) N3 has left child N2 and right child N5, and N5 has a left child with value 3 (d) Given the above implementation, a new node with value 3 is both the right child of N2 and the left child of N5. Q9: A vector is sorted in descending order with the insertion sort algorithm. After 4 iterations of the outer loop, he vector holds values as shown: 84, 31, 25,7, 2, 3, 5, 12 After the next (outer) iteration, the vector values will be stored as: (a) 84, 31, 25, 12, 2,3,5,7 (b) 84, 31, 25, 3, 12, 7,5, 2 (c) 84, 31, 25, 7, 3, 2,5, 12 (d) 84, 31, 25, 7, 12, 5, 3, 2Explanation / Answer
Q.8.
If we see first if block, if x is less than or equal to value at node (N3), then it will go to the left child, if left child is not there it will be added as left child, if its there then the function is called on left child node.
Now we have N3 with value 3, and we are truying to insert 3. Now 3 == 3, So it will go to its left child which is N2. As left child is already there for N3, so it will call N2.insert(3)
Now 3> 2, so it will go to right child of N2, as, N2 is not having any right child, So it will be added as right child of N2.
So correct option is b) N3 has left child as N2 and right child as N5. and N2 has right child as N3.
As per chegg policy I have solved the first question. I am providing the answer of Q.9 as well , but if you need its explanation, Please post it as a different question
Q.9 c) 84 31 25 7 3 2 5 12
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.