Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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,

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions