Problem: Sort with a Search Tree

In this chapter we sorted by adding elements to a heap and taking them out in order. A binary search tree can sort the same way, and you already built one in the search tree chapter.

Recall from the search tree chapter that an in-order traversal of a binary search tree visits its values from smallest to largest.

Before opening the solution, answer two questions:

  • What is the total cost of treeSort?
  • What happens to that cost if the array is already sorted?