Understanding Priority Queues and Heaps in CSE 373 Lecture

Slide Note
Embed
Share

Today's lecture in CSE 373 covers the Priority Queue Abstract Data Type (ADT), the properties of heaps, and their implementations. Key topics include the completeness property of heaps, different priority queue implementations such as the binary search tree for faster insert and find operations, and unique demands of Priority Queues compared to Binary Search Trees (BST). The lecture also discusses the properties of Binary Search Trees and Heap Order Property in detail, highlighting the differences in implementation compared to BSTs. Overall, students will gain insights into efficient data structures for managing priorities and understanding heap properties for effective implementations.


Uploaded on Sep 14, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. CSE 373 MARCH 31 PRIORITY QUEUES AND THE HEAP

  2. ASSORTED MINUTIAE Weiss readings On course website HW1 is out (patch out tonight) Eclipse users will get some help Test 5 fix 143 review Monday, time/location TBA

  3. TODAYS LECTURE Priority Queue ADT Heap DS Heap Property Completeness property Implementation

  4. REVIEW FROM LAST WEEK Priority Queue Data enqueued with a priority Lower priority data dequeue first Maintain queue principle? Implementations? Array and Linked List both have serious flaws.

  5. PRIORITY QUEUE Priority queue implementations? Binary search tree? Faster insert Find? Always deleting the smallest (left- most) element Maintaining FIFO? Changing priority?

  6. PRIORITY QUEUE Want the speed of trees (but not BST) Priority Queue has unique demands Other types of trees? Review BST first

  7. PROPERTIES (BST) Tree (Binary) Root (Two) Children No cycles Search Comparable data Left child data < parent data Smallest child is at the left most node

  8. PROPERTIES (BST) Binary tree may be useful Search property doesn t help Always deleting min Put min on top!

  9. HEAP-ORDER PROPERTY Still a binary tree Instead of search (left < parent), parent should be less than children How to implement? Insert and delete are different than BST

  10. HEAP-ORDER PROPERTY Still a binary tree Instead of search (left < parent), parent should be less than children How to implement? Insert and delete are different than BST

  11. HEAP EXAMPLE Only looking at priorities Insert something priority 4

  12. HEAP EXAMPLE 4 Now insert priority 6? Should come after 4, but no preference right over left? Solution: fill the tree from top to bottom left to right.

  13. HEAP EXAMPLE 4 null 6 Now insert 2.

  14. HEAP EXAMPLE 2 4 6 Now insert 2.

  15. HEAP EXAMPLE 2 4 6 Is this the only solution that maintains the heap property? Is any one better than the other?

  16. COMPLETENESS Filling left to right and top to bottom is another property - completeness

  17. HEAPS Heap property (parents < children) Complete tree property (left to right, bottom to top) How does this help? Array implementation

  18. HEAPS Insert into array from left to right For any parent at index i, children at 2*i+1 and 2*i+2 0 1 2 3 4

  19. HEAPS How to maintain heap property then? Parent must be higher priority than children Two functions percolate up and percolate down DRAWN NOTES HERE

  20. HEAPS Does the heap work for the Priority Queue problem? FIFO preservation? No. Only comparisons are priority.

  21. NEXT WEEK Look more closely at heap functions and runtimes Beginning of algorithm analysis

Related


More Related Content