Questions tagged [treap]

A treap is a form of a binary search tree data structure that maintains a dynamic set of ordered keys and allows binary searches among the keys.

A treap (tree+heap) is a Cartesian tree in which each key is given a (randomly chosen) numeric priority. As with any binary search tree, the inorder traversal order of the nodes is the same as the sorted order of the keys.

The structure of the tree is determined by the requirement that it be heap-ordered: that is, the priority number for any non-leaf node must be greater than or equal to the priority of its children.

Thus, as with Cartesian trees more generally, the root node is the maximum-priority node, and its left and right subtrees are formed in the same manner from the subsequences of the sorted order to the left and right of that node.


Useful links


Related tags

30 questions
1
vote
0 answers

Balanced search tree (Treap) with multiple equal keys

I have to create a balanced search tree with multiple equal keys. I implemented the function I need: #include #include #include typedef struct tip_nod { int key, priority; struct tip_nod *left, *right; } NOD; …
Tandura
  • 866
  • 2
  • 7
  • 19
1
vote
1 answer

What should I choose for an easy to code balanced binary search tree?

I would like to know which balanced BST would be easy to code in C++, and still have a complexity roughly equal to O(logn). I've already tried Red Black trees, but would like an alternative that is less complex to code. I have worked with Treaps in…
Tamim Addari
  • 7,591
  • 9
  • 40
  • 59
1
vote
1 answer

Prim's Algorithm with Treaps

Can Prim's algorithm be implemented by treaps to speed up the execution because a normal heap would pose a problem in updating the value of keys while storing vertices in heaps which otherwise would require O(V) space to store location of vertices…
silentseeker
  • 416
  • 5
  • 14
1
vote
1 answer

Error in deleting treap

i have a procudere deletes for my treap, and on the line p=merge(l, merge(m, rs)); i have error error: non-const lvalue reference to type 'nodeptr' (aka 'node *') cannot bind to a temporary of type 'nodeptr' So here is implementation of deletes and…
ratkke
  • 469
  • 1
  • 4
  • 13
1
vote
1 answer

Using "Treap" to compare two set

I want to use Treap structure,but I don't familiar with this type of tree well. I have two set and i want to write a method to compare them with Treap. This method should return a value that show the similarity of two set. (My work is retrieve a set…
SahelSoft
  • 615
  • 2
  • 9
  • 22
0
votes
0 answers

Why is the height of my Treap almost double the expected height?

I was coding up a Generic Treap data structure as an exercise, and then performed an analysis on the size (number of elements) of the treap, height of the treap, as well as the treap constant (height / log10(size)). I found that the height of my…
0
votes
2 answers

Errors from valgrind (Treap)

Valgrind throws errors in this program when implementing the Treap data structure. Can't figure out how to fix this. Tried to write a destructor, nothing changed. The rest of the code is not included for simplicity. The error is in this part of the…
user16949111
0
votes
0 answers

Implementation of the Treap Add function

Hello so I am working on my treap method which requires a Stack to track the list of nodes that it goes through, and maintains the Heap Property by doing a list of rotations at the end. However, when I run this code it gives me…
toina
  • 1
  • 1
0
votes
0 answers

Dynamic graph using Treap data structure

I am trying to implement Dynamic graph using Treap data structue. Here is node structure: class TreapNode { public: int key; int priority; TreapNode* left, *right; …
tushar
  • 313
  • 4
  • 10
0
votes
1 answer

How to insert a node onto a Treap with three arguments

I am having issues inserting a Treapnode into a treap. It takes in 3 arguments. add(E key, P priority, treapnode x). I have tried many things and keep getting a null pointer exception. I have tried checking for null cases in both the left and the…
nv_twistt
  • 3
  • 2
0
votes
1 answer

Using a stack to store treap nodes when adding new nodes. Why am I getting an EmptyStackException?

I'm building a treap class in Java. Below is my function for adding new nodes to the treap. The process is: traverse down to bottom of treap (while adding each node in the path to a local stack) only worrying about the BST structure at first, then,…
0
votes
1 answer

Can rotations in treap violate it's heap-ordering or the binary search tree order?

I'm not sure if I can violate treap's heap-ordering or it's binary search tree like structure with left and/or right rotation methods. This is the code for left rotation typename BinarySearchTree::BSTTreeNode* rightSon =…
dodekja
  • 537
  • 11
  • 24
0
votes
2 answers

priority generation in treap data structure

I'm studying the treap data structure. When inserting node, treap radomly generate node's priority. But what if 69 node's generated priority is 13 in the picture above? Parent's priority must higher than child's priority. Do treap's binary tree…
mjkim
  • 581
  • 3
  • 6
  • 19
0
votes
1 answer

height of binary tree in java taking no parameters

I know there are many functions to be found out there where you can easily get the height of the Binary search tree by recursively calling the function and using the root of the node as the parameter every time for the left and right subtree. But…
Nova
  • 1
  • 1
  • 2
-1
votes
3 answers

What is the difference between passing a pointer to function and passing reference of pointer to function?

So, I have a structure struct node { node * l; node * r; }; Then, there is typedef node* tnode; What I don't understand is this function: void tsplit(tnode t, tnode &l, tnode &r, int x) As I get it, we pass t to tsplit() as a pointer to a…
zardos
  • 5
  • 3
1
2