CSE116 4-21-2010 Notes

CSE116 4-21-2010 Notes - The tree is heap ordered Balance...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Priority Queues A priority queue is a queue in which items are ordered according to their priorities. Traditionally, low numeric values for priorities correspond to high priorities. Implementation Linear list – sorted list in which items are ordered by priority Heap - A binary tree which maintains its items according to a heap order Aside : the queue we saw earlier is a special case of a priority queue in which the priority of an item corresponds to how long it has been in the queue. A head is a binary tree that maintains two invariants: 1) Order property 2) Structure/balance property Heap order Property (min version) For every non-empty heap the value at the root is less than any value in either of its children.
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The tree is heap ordered Balance Property Basic idea : do not start a new level in the tree until the previous one is full In our implementation, the condition is: For every non-empty heap, the size of the left subtree is either the same size as the right subtree, r it is one larger Either: |L| = |R| Or: |L| = |R| + 1 Insertion into a heap: 1a) insert a new item (recursively) into the right subtree 1b) swap the left and right subtrees as we go along 2) Restore the order condition by percolating up any out – of –order item along the insertion path Ex: show what an initially empty min- heap looks like as each of the following items is inserted: 40 60 90 50 20 30 10 D) …...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern