Skip to main content
Contents Index
Dark Mode Prev Up Next Scratch ActiveCode Profile
\(
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
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.
7.
Implement a binary heap as a max heap.
You have attempted
of
activities on this page.