Question: 4. [4 marks If we insert a set of n items into a binary search tree the resulting tree may be unbalanced. In the lectures,

 4. [4 marks If we insert a set of n items

4. [4 marks If we insert a set of n items into a binary search tree the resulting tree may be unbalanced. In the lectures, we examined how AVL trees can be used to solve this 'unbalanced' problem In this question, you will investigate an alternative approach using a treap. A treap is a binary search tree with a modified way of ordering the nodes with respect to the key values ki and a min-heap with respect to the priority pi. Consider a set of records R - fri,r2,... Tn^. Each record r, has a key ki and independently of ki a priority pi. We will write a record as (ki,pi). The records are inserted into the treap such that the binary-search-tree property based on the record's key value is maintained and the priorities obey the min-heap order property You may assume that all key values and priorities are positive integers, and all priorities are distinct as well. a) Draw the treap T that contains the following seven record values (b) Write an algorithm BuilDTREAP(R) in pseudocode to construct a treap from the set of records R passed as an argument to your function. (Hint: use recursion) You must include appropriate comments in your pseudocode. Your pseudocode should make reasonable assumptions about how trees are represented The notation/syntax/style used in question 3 should also be adopted here. In addition, you may like to use: T- new Tree to create a new tree . T.key

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!