0% found this document useful (0 votes)
12 views2 pages

Max-Heap Operations and Algorithms Guide

The document contains in-class exercises for a course on algorithms, focusing on heaps and related concepts. It includes tasks such as explaining max-heap properties, representing heaps as arrays, extracting maximum elements, adding new elements, and building heaps from given sets of numbers. Additionally, it covers the application of the HeapSort algorithm on created max-heaps.

Uploaded by

eng.aishaasif
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Max-Heap Operations and Algorithms Guide

The document contains in-class exercises for a course on algorithms, focusing on heaps and related concepts. It includes tasks such as explaining max-heap properties, representing heaps as arrays, extracting maximum elements, adding new elements, and building heaps from given sets of numbers. Additionally, it covers the application of the HeapSort algorithm on created max-heaps.

Uploaded by

eng.aishaasif
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MIDDLE EAST TECHNICAL UNIVERSITY, NORTHERN CYPRUS CAMPUS

CNG315 Algorithms – In-class Exercises for Lecture 4

Topics: What is a heap?, Heapify Algorithm & Analysis, BuildHeap Algorithm & Analysis, HeapSort Algorithm
& Analysis, Heaps & Priority Queues.

1. Explain how the following tree satisfies the conditions to be a max-heap.

17

15 11

9 8 10 4

3 5 1

2. Show the array representation of the max-heap given in Q1.

3. Extract (or delete) the maximum element from the max-heap given in Q1. Show both the tree and array
representations.

4. Add 16 to the heap given in Q1. Show both the tree and array representations.

Page 1 of 2
5. Use {7, 20, 18, 15, 5, 25} to create a max-heap by using the BuildHeap operation. Show both the tree and
array representations.

6. Use the max-heap created in Q5 and apply the HeapSort algorithm. Show both the tree and array
representations.

Page 2 of 2

You might also like