MCQs
Sort the given input, find the median element among them, make it as root and construct left and right subtrees with elements lesser and greater than the median element recursively. this ensures the subtrees differ only by height 1.
Since all the elements lesser than a given node will be towards the left, iterating to the leftmost leaf of the root will give the minimum element in a binary search tree.
This is an application of stack.
i) from root search for the node to be deleted
ii)_____________________________________
iii) delete the node at _____________________
what must be statement ii) and fill up statement iii)
We just replace a to be deleted node with last leaf node of a tree. this must not be done in case of BST or heaps.
Array cannot represent arbitrary shaped trees it can only be used in case of complete trees hence option a must be done which is one of several ways to use array in such situations.
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
The above given steps are for sorting a cartesian tree. cartesian sort is benificial in case of partially sorted set of elements. a cartesian
sort can be considered as a selection or heap sort maintaining a priority queue.
Though both trees are balanced, when there are more insertions and deletions to make the tree balanced, AVL trees should have more rotations, it would be better to use red-black. but if more search is required AVL trees should be used.
Splay trees can be used for faster access to recently accessed items and hence used for cache implementations.
The left and right children are added first to the stack, followed by the node, which is then popped. Post-order follows LRN policy.
Since you have to go through all the nodes, the complexity becomes O(n).