Тёмный

Treap (Tree + Heap) Data Structure - Tutorial with Statistical Analysis 

Stable Sort
Подписаться 12 тыс.
Просмотров 14 тыс.
50% 1

A computer science data structure called "Treap" is a combination of a Binary Search Tree and a Heap. This introductory tutorial explains how Treap data structure uses randomly generated numbers, called "priority" to construct and maintain a reasonably balanced tree.
The tree is constructed as if it’s a heap, with maximum priority value being at the root of the tree. Note that the tree construction needs to satisfy two conditions simultaneously:
1) each left child value is smaller than its parent’s, while each right child value is greater than its parent’s (this is the old binary search tree rule).
2) each child priority is smaller than its parent's priority (this is the max heap rule)
To we ensure that both of these conditions are satisfied, when inserting a node, we still walk down from the root, following the rules of a standard binary search tree (BST), comparing values to each other - we go left if the value is smaller than the parent, right if the value is bigger than the parent, and eventually create a new leaf node. Then, if we find that the priority of the node is greater than parent’s priority, we do tree rotations to fix this.
Cecilia R. Aragon and Raimund Seidel, in their 1989 paper, called "Randomized Search Trees", show that while there is no hard guarantee that the resulting tree will be balanced, the probability of the height of a Treap with n nodes being greater than natural log of n by a factor of some constant c, is bounded by a formula.
faculty.washington.edu/aragon/...
In computer science, the treap and the randomized binary search tree are two closely related forms of binary search tree data structures that maintain a dynamic set of ordered keys and allow binary searches among the keys:
en.wikipedia.org/wiki/Treap
Avrim Blum's CMU lecture that makes use of "Hoeffding’s inequality" to analyze dept of a treap:
www.cs.cmu.edu/~avrim/451f11/...
Written and narrated by Andre Violentyev

Опубликовано:

 

27 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 34   
@neeter99
@neeter99 4 года назад
Probably the best video on Treaps, hope your channel gets bigger!
@stablesort
@stablesort 4 года назад
Thanks, Ameet! I'll be posting more and more tutorials. Please subscribe and share!
@maridavies3425
@maridavies3425 4 года назад
Nice! It’s great that you mention the statistical guarantees made about the tree structure being balanced.
@walt3719
@walt3719 Год назад
Good enough for government work is always my favourite statement to use
@stablesort
@stablesort Год назад
hahaha😂
@WAAGOM
@WAAGOM Год назад
This is the best video on Treaps! Thanks for your help understanding this.
@pratyushtiwari6486
@pratyushtiwari6486 4 года назад
Your explanations are awesome and such a calm environment.
@stablesort
@stablesort 4 года назад
Glad you like them!
@Tracks777
@Tracks777 4 года назад
lovely stuff
@aliberatcetin6765
@aliberatcetin6765 Год назад
what a great channel I discovered
@tahakhany3103
@tahakhany3103 2 года назад
Thanks for the tutorial!
@EXcoWx223
@EXcoWx223 4 года назад
Great video, thank you so much!
@stablesort
@stablesort 4 года назад
Glad you enjoyed it!
@pietertjeboersma6586
@pietertjeboersma6586 3 года назад
Awesome explanation, thank you!
@stablesort
@stablesort 3 года назад
You are very welcome! Cheers!
@robertogarcia9966
@robertogarcia9966 3 года назад
Awesome tutorial, please keep making videos like this.
@stablesort
@stablesort 3 года назад
Thanks! A new episode is a little overdue but it is in the making =)
@archiefayzullaev4585
@archiefayzullaev4585 3 года назад
Great Explanation! Thank you! I hope you will keep working on the channel !
@stablesort
@stablesort 3 года назад
Thanks for the compliment! I do have quite a few more topics to cover =)
@ghumataarti
@ghumataarti 2 года назад
Great video sir, thank you! ❤️
@futurexy3931
@futurexy3931 4 года назад
Thanks! Your video is awesome ,I learn a lot
@stablesort
@stablesort 4 года назад
Wonderful, thanks for the feedback! If there are other subjects that you'd like me to discuss, feel free to let me know. Cheers!
@Avighna
@Avighna 6 месяцев назад
std::set has finally been un-blackboxed. Thank you! (yes, I know it uses RB trees, but treaps are a valid way to do it too)
@kidusadugna653
@kidusadugna653 3 года назад
"It probably won't be perfectly balanced, but good enough for government work" 😂😂😂😂😂😂😂
@stablesort
@stablesort 3 года назад
Indeed =)
@dakshays6375
@dakshays6375 3 года назад
make video on Trie data structure
@stablesort
@stablesort 3 года назад
Thanks for the suggestion. I have considered it but, it seems that this topic has been covered pretty well already... It is, however, one of my favorite data structures that actually does come into play every now and then in the "real world".
@sineltor
@sineltor 2 года назад
As for use cases, could you store a treap in an array like you can with a heap? If so, you'd probably end up with better performance than AVL trees because of cache locality.
@stablesort
@stablesort 2 года назад
That's a neat idea! May be there is a way but my immediate knee-jerk reaction is that it may not be possible since the 1st phase of the algorithm uses the tree property when inserting a node. But hey, let me know if you come up with an implementation!
@dawodujohnson
@dawodujohnson 2 года назад
Are you related to secondthread on codeforces?
@stablesort
@stablesort 2 года назад
No, no relation
@alex-gz7ud
@alex-gz7ud 3 года назад
Awesome explanation! I'd like to give you 1000 likes if I can.
@stablesort
@stablesort 3 года назад
A thousand thanks!!!
Далее
РУБИН - ЗЕНИТ: ВСЕ ГОЛЫ
01:03
Просмотров 162 тыс.
Skip Lists
15:36
Просмотров 37 тыс.
KD-Tree Nearest Neighbor Data Structure
6:39
Просмотров 109 тыс.
How Dijkstra's Algorithm Works
8:31
Просмотров 1,3 млн
The moment we stopped understanding AI [AlexNet]
17:38
Просмотров 787 тыс.
AlgorithmsThread 9: Treaps!
44:19
Просмотров 23 тыс.
РУБИН - ЗЕНИТ: ВСЕ ГОЛЫ
01:03
Просмотров 162 тыс.