Assignment 2
Assignment 2
c) As written, count-sort only works if all of the keys have different values. Explain
how to modify count-sort to work if multiple keys have the same value.
b) Design an algorithm for the following operation for a binary tree T of size n, and
analyze its worst-case running time. Your algorithms should avoid performing
traversals of the entire tree.
preorderNext(v): return the node visited after v in an preorder traversal
c) Ilustrate the execution of the heap-sort algorithm on the following input sequence:
(26, 35, 16, 24, 10, 23, 19, 13, 39, 15).
What is the running time of your method (ignore input and output operations), in terms of
n and k, assuming the sequence is implemented with a doubly linked list? What if the
sequence is implemented with an array?
Note that the main objective of this question is to implement the solution for the “hot
potato” problem, not to implement Sequence – you can use the implementation of
Sequence from the textbook’s web site (but make sure it works!) .