0% found this document useful (0 votes)
27 views3 pages

Solution of Assignment No. 3 CS301: Mc190401514 Name: Imran Kashif

The document describes solving two problems related to min heaps. It shows a diagram of a min heap and explains that each parent node is less than its child nodes, making it a valid min heap. It then shows the steps of inserting the number 1 into an existing min heap array, maintaining the min heap property by bubbling 1 up until it is in the correct position.

Uploaded by

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

Solution of Assignment No. 3 CS301: Mc190401514 Name: Imran Kashif

The document describes solving two problems related to min heaps. It shows a diagram of a min heap and explains that each parent node is less than its child nodes, making it a valid min heap. It then shows the steps of inserting the number 1 into an existing min heap array, maintaining the min heap property by bubbling 1 up until it is in the correct position.

Uploaded by

Imran Kashif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Mc190401514 Name: Imran kashif

Solution of assignment No. 3 CS301


Solution: (a)

3
4

6 16 19 24

8 11 20 23 30

The above diagram is min heap because each parent node is less than child node.

Solution: (b)
Step 1:

Data 2 3 4 6 16 19 24 8 11 20 23 30 1
Array 0 1 2 3 4 5 6 7 8 9 10 11 12 13
index

3
4

6 16 19 24

8 11 20 23 30 1
Step 2:

Data 2 3 4 6 16 1 24 8 11 20 23 30 19
Array 0 1 2 3 4 5 6 7 8 9 10 11 12 13
index

3
4

6 16 1 24

8 11 20 23 30 19

Step 3:

Data 2 3 1 6 16 4 24 8 11 20 23 30 19
Array 0 1 2 3 4 5 6 7 8 9 10 11 12 13
index

3
1

6 16 4 24

8 11 20 23 30 19
Step 4:

Data 1 3 2 6 16 4 24 8 11 20 23 30 19
Array 0 1 2 3 4 5 6 7 8 9 10 11 12 13
index

3
2

6 16 4 24

8 11 20 23 30 19

The above diagram is min heap because each parent node is less than child node.

**********************************************************************************

You might also like