Docsity

Heap Sort Algorithm: Concepts and Implementation, Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
Date: December 4, 2020
RUTGERS UNIVERSITY
The State University of New Jersey
School of Engineering
Department of Electrical and Computer Engineering
14:332:351 Programming Methodology โ€“ II Fall 2004
Heap-Sort
1. What are the minimum and maximum numbers of elements in a heap of height h?
2. Where in a heap might the smallest element reside?
3. Is an array that is in reverse sorted order a heap?
4. Is the sequence <23, 17, 14, 6, 13, 10, 1, 5, 7, 12> a heap?
5. Using figure 7.2 as a model, illustrate the operation of Heapify (A, 3) on the array A = <27,
17, 3, 16, 13, 10, 1, 5, 7, 12, 4, 8, 9, 0>.
6. What is the running time of heap sort on an array A of length n that is already sorted in
increasing order? What about decreasing order?
7. Show that the running time of heap sort is ๏—(nlgn).
8. Show how to implement a FIFO queue with a Priority Queue.
9. Show how to implement a Stack with a Priority Queue.
10. Give a ๏—(n lg k)-time algorithm to merge k sorted lists into one sorted list, where n is the
total number of elements in all the input lists. (Hint: Use a heap for k-way merging).
Page 1 of 1
Readings:
๏‚ทRead Ch 7 (Heap sort) from Cormen et al before next lecture.

Partial preview of the text

Download Heap Sort Algorithm: Concepts and Implementation and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

Date: December 4, 2020

RUTGERS UNIVERSITY

The State University of New Jersey School of Engineering Department of Electrical and Computer Engineering 14:332:351 Programming Methodology โ€“ II Fall 2004

Heap-Sort

  1. What are the minimum and maximum numbers of elements in a heap of height h?
  2. Where in a heap might the smallest element reside?
  3. Is an array that is in reverse sorted order a heap?
  4. Is the sequence <23, 17, 14, 6, 13, 10, 1, 5, 7, 12> a heap?
  5. Using figure 7.2 as a model, illustrate the operation of Heapify (A, 3) on the array A = <27, 17, 3, 16, 13, 10, 1, 5, 7, 12, 4, 8, 9, 0>.
  6. What is the running time of heap sort on an array A of length n that is already sorted in increasing order? What about decreasing order?
  7. Show that the running time of heap sort is ๏—(nlgn).
  8. Show how to implement a FIFO queue with a Priority Queue.
  9. Show how to implement a Stack with a Priority Queue.
  10. Give a ๏—(n lg k)-time algorithm to merge k sorted lists into one sorted list, where n is the total number of elements in all the input lists. (Hint: Use a heap for k-way merging).

Page 1 of 1

Readings: ๏‚ท Read Ch 7 (Heap sort) from Cormen et al before next lecture.