Heaps & Priority Queues in Python

  Рет қаралды 56,362

NeuralNine

NeuralNine

2 жыл бұрын

Today we learn how to use heaps in Python. Heaps are efficient implementations of priority queues.
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
🐍 The Python Bible Book: www.neuralnine.com/books/
💻 The Algorithm Bible Book: www.neuralnine.com/books/
👕 Programming Merch: www.neuralnine.com/shop
🌐 Social Media & Contact 🌐
📱 Website: www.neuralnine.com/
📷 Instagram: / neuralnine
🐦 Twitter: / neuralnine
🤵 LinkedIn: / neuralnine
📁 GitHub: github.com/NeuralNine
🎙 Discord: / discord
🎵 Outro Music From: www.bensound.com/

Пікірлер: 32
@dhbroad2660
@dhbroad2660 Жыл бұрын
Thank you for this! So many other videos on heaps just speak about the theory, but don't show any implementation or manipulation.
@Gooloso98
@Gooloso98 2 жыл бұрын
nice video, remind me of data structures classes. min heap its great and efficient. Usually its implemented on top of arrays, although its best viewed as graphs. min heap always keep a min height state since the height of the tree generated will be log2(numbers inside).
@rafaelsartoricavalcante4253
@rafaelsartoricavalcante4253 5 ай бұрын
Best video on subject, thanks
@vikasjha1064
@vikasjha1064 Күн бұрын
Brilliant mate, ,Please make these type of explanation for other Data Structure also. Thanks
@takshdhabalia1476
@takshdhabalia1476 2 жыл бұрын
Great video Loved the content Keep it up
@adarshsasidharan254
@adarshsasidharan254 Жыл бұрын
Brilliant video
@lzdps
@lzdps 2 жыл бұрын
awesome!
@servantofthelord8147
@servantofthelord8147 Күн бұрын
Thank you!
@tcgvsocg1458
@tcgvsocg1458 2 жыл бұрын
can you do a video on screen recorder but no import with vanilla pyhton please
@anthonyrojas9989
@anthonyrojas9989 3 ай бұрын
Your videos are awesome, but the music is loud af in the beginning and then the voice audio is way lower. I think that could be better
@soniahandle
@soniahandle Жыл бұрын
hi, can someone explain what "maintaining heap invariant" means?
@serratedhumor8468
@serratedhumor8468 10 ай бұрын
invariant = unchanging, immutable.
@abhishekpardeshi5701
@abhishekpardeshi5701 Ай бұрын
you did not mention priority queue code
@disrael2101
@disrael2101 2 жыл бұрын
What for / where it's used for mainly
@jerrylin4980
@jerrylin4980 Жыл бұрын
When you need to insert and retrieve multiple times while the order of the list needs to be maintain, I think it's good to use a heap.
@Pickolzi
@Pickolzi 4 ай бұрын
I am still new to this topic but I will try to explain why I believe it is better to use heaps. Say you have a list of 10,000 elements and that you always need the lowest or highest number. If you are constantly adding and removing elements from the array, after each append() or pop(), you will need to sort the list to maintain the order of the list. 1. Using list.sort() will at worst case run in O(n*logn) run time 2. iterating through each item of the list to find the proper position to place the new element will at worst case run in O(n) run time 3. inserting an element in a heap will at worst case run in O(logn) run time So to insert a new element into a 10,000 element array and maintain order would take 1. ~130,000 iterations for list.sort() 2. ~10,000 iterations for iterating the array 3. ~14 iterations for a heappush() So imagine you have 10,000 people trying to buy tickets online, each person has a rank depending on previous activity. You can store their data in a tuple (rank, user_id). So when tickets start to become available for sale and the website wants to prioritize higher ranked customers, using a heap will allow the website to run a lot faster especially with a large audience.
@disrael2101
@disrael2101 4 ай бұрын
cool thanks for the explanation, it makes sense only the math formula i didn't understand as you didn't explain what each parameter means.. also what's the equalivent of heap in js? as i work with js for webapps@@Pickolzi
@AryanSingh-eq2jv
@AryanSingh-eq2jv 4 ай бұрын
free palestine
@disrael2101
@disrael2101 3 ай бұрын
in ur dreams :DD@@AryanSingh-eq2jv
@AryanSingh-eq2jv
@AryanSingh-eq2jv 4 ай бұрын
i love you
@user-vm9hl3gl5h
@user-vm9hl3gl5h 6 ай бұрын
valid heap: 2:12 of kzbin.info/www/bejne/npzcq5aCoNKieLs => parent should be smaller than children (min-heap).
@digvijaynadimetla9934
@digvijaynadimetla9934 2 жыл бұрын
devudivi sami
@niteshanthony2324
@niteshanthony2324 Жыл бұрын
Hey everyone ik its pretty late but i just wanna tell u all to take it easy, relax, pray to GOD and have and trust in GOD as well as believe in his one and only son Jesus and to repent of your sins. hope u have an amazing day
@dheerajsharma355
@dheerajsharma355 Жыл бұрын
Hare Krishna!!
@Mr_Clumsee
@Mr_Clumsee Жыл бұрын
Jai Shree Ram!!
@mrsteth993
@mrsteth993 11 ай бұрын
Jesus isn't real.
@caio-jl6qw
@caio-jl6qw 11 ай бұрын
Bot
@xEpsi
@xEpsi 7 ай бұрын
stop advertising jesus in a python tutorial
Heaps, heapsort, and priority queues - Inside code
19:01
Inside code
Рет қаралды 73 М.
2.6.3 Heap - Heap Sort - Heapify - Priority Queues
51:08
Abdul Bari
Рет қаралды 2 МЛН
WHO DO I LOVE MOST?
00:22
dednahype
Рет қаралды 79 МЛН
Мы никогда не были так напуганы!
00:15
Аришнев
Рет қаралды 5 МЛН
Please be kind🙏
00:34
ISSEI / いっせい
Рет қаралды 192 МЛН
10 Nooby Mistakes Devs Often Make In Python
24:31
Indently
Рет қаралды 48 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 296 М.
Deques can be FASTER than lists in Python
12:17
Carberra
Рет қаралды 26 М.
8 patterns to solve 80% Leetcode problems
7:30
Sahil & Sarra
Рет қаралды 218 М.
Please Master These 10 Python Functions…
22:17
Tech With Tim
Рет қаралды 70 М.
What Is a Binary Heap?
8:45
Spanning Tree
Рет қаралды 181 М.
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 271 М.
Top 6 Coding Interview Concepts (Data Structures & Algorithms)
10:51
Makefiles in Python For Professional Automation
13:43
NeuralNine
Рет қаралды 39 М.
Игровой Комп с Авито за 4500р
1:00
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 1,8 МЛН
Урна с айфонами!
0:30
По ту сторону Гугла
Рет қаралды 8 МЛН