15) Heap - Insert 10 values into a min-heap from a file...

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

View Full Document Right Arrow Icon
Insert 10 values into a min-heap from a file. Display the data, level by level. Then delete 5 items. After each delete, display the heap, level by level. Heaps There are two types of heap: min-heap and max-heap. Elements in the heap are not perfectly ordered as in a binary search tree. Think of min heaps like binary trees with specific conditions. The heap has two basic properties: Order property Min-heap: The value of each node is smaller than or equal to the values stored in each of its children. Max-heap: The value of each node is bigger than or equal to the values stored in each of its children Shape property It has to be a complete tree.
Image of page 1

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

View Full Document Right Arrow Icon
Given a max-heap, they all have the shape property, but some violate the order property.
Image of page 2
What is a heap used for: Priority Queues Think of a priority queue as a kind of bag that holds priorities. You can put one in, and you can take out the current highest priority. A priority queue is different from a "normal" queue, because instead of being a "first- in-first-out" data structure, values come out in order by priority. A priority queue
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the 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