Q. No.1 a) Consider a binary search tree (BST) that isinitially empty. Draw the
ID: 3615144 • Letter: Q
Question
Q. No.1
a) Consider a binary search tree (BST) that isinitially empty. Draw the tree that will result if the followingnumbers are inserted in the order given: 7, 3, 8, 1, 6, 2, 9,5.
b) What basic operations we can perform on thebinary tree of part (a)
Q.No.2 Answer the Following Questions:
(a)
Suppose we want a function to change the state of an object. Butwe don’t want to send a copy to the function. The objectcould be large and copying it costly in terms of time.
Which of the following is the best solution to do this andwhy?
1) We will use pointers
2) We will use pass by reference
(b) What is dangling reference? Explain withhelp of an example.
Explanation / Answer
Passing objects by pointer communicates the identity of the objectbeing passed instead of a copy of the object because the objectcould be large so it avoids the cost of copying the object andallows the sender and receiver to share the same object. In thesimple form, passing objects by pointer also allows the sender toobserve any changes that the receiver might make in the sharedobject. Often times, observing these changes is how thecommunication between the sender and the receiver is achieved. Inother cases it is desired that the object be protected againstchange by the receiver.
Using pointers also allows us high performance and compact memoryfootprint so we will use pointers if we want a function to changethe state of an object without sending a copy to thefunction.
b)
Dangling Refernce
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.