-2

I am having really hard time with this and I don't know how to approach it - would really appreciate your help:

A company tries to build a SP tree data structure so that each intersection contains two keys: a sorting key skey that gives SP the abilities of a binary search tree, and a pkey key that gives SP the abilities of a minimum heap(assuming that all of the pkey keys are different from one another).

How can I show that there exists singular(single) data structure SP that consists of n pairs of keys(skey, pkey)?

I mean, because of pkey(the min-heap),it says that the heap tree will be defined so that each of its sons are larger in value than their parents. But, because of the skey (the binary tree), it means that only on the right side there will be elements with value larger than the parent(the left should be less, but i don't know how it combines with the pkey requirement - since it the sons should be with a higher value than the parent). I really don't understand it - does the tree that should be obtained looks like a line towards the right?

I really don't understand and would really appreciate if you guys could help me with that.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • So what is (an) SP here? – H H Jun 16 '18 at 21:40
  • You could create a node that has two sets of links: the right and left links for the binary search tree, and the right and left links for the min heap. – Jim Mischel Jun 16 '18 at 21:46
  • SP is the name of the data structure. jim, how could i use that to show that exists only a singular(single) datastructure SP that consists of n pairs of keys? – BeginningMath Jun 16 '18 at 21:52
  • @JimMischel, could you please show me a pseudocode to what you said? it's interesting and i can't think of how i can enter a pair(skey, pkey) into SP – BeginningMath Jun 16 '18 at 22:11
  • @HenkHolterman `So what is (an) SP here?` guessing: from *S*econdary and *P*rimary key. Or *S*earch and *P*riority, which doesn't look "reversed". – greybeard Jun 17 '18 at 17:14

1 Answers1

2

Im just have the same question in my algorithms course ("the open university of Israel").

try to use treap (treap = tree + heap) you can see here how it works:

you can see a good example for it in exercise 13-4 in the book "Introduction to algorithms".

here is also some nice explanation for this:

https://threads-iiith.quora.com/Treaps-One-Tree-to-Rule-em-all-Part-1

here is some solution for that: https://github.com/gzc/CLRS/blob/master/C13-Red-Black-Trees/problem.md

and the translation from chains is:

Treap will insert the nodes into a normal binary tree in the order of their priorities. If the Treap of n-1 nodes is certain, because the INSERT algorithm is a deterministic algorithm, the Treap that can get n nodes is also determined.

Rea Haas
  • 2,018
  • 1
  • 16
  • 18