Skip to main content
Logo image

Problem Solving with Algorithms and Data Structures using Kotlin The Interactive Edition

Section 9.7 Trees: Exercises

Exercises Exercises

1.

Generate a random list of integers. Show the binary heap tree resulting from inserting the integers on the list one at a time.

2.

Using the list from the previous question, show the binary heap tree resulting from using the list as a parameter to the heapify method. Show both the tree and list form.

3.

Consider the following list of integers: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]. Show the binary heap resulting from inserting the integers one at a time.

4.

Consider the following list of integers: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]. Show the binary heap resulting from inserting the integers one at a time.

5.

Create a binary heap with a limited heap size. In other words, the heap only keeps track of the \(n\) most important items. If the heap grows in size to more than \(n\) items the least important item is dropped.

6.

Using the heapify method, write a sorting method that can sort a list in \(O(n\log{n})\) time.
You have attempted of activities on this page.