Algorithms and OOD (CSC 207 2014S) : EBoards

# CSC207.01 2014S, Class 47: Heap Sort

Overview

• Preliminaries.
• Upcoming work.
• Questions.
• Heap sort.
• Can we do better?
• Lab.

## Preliminaries

• Don't forget to register!
• I need two graders for next semester who can do detailed comments. Yes, I will provide training.
• I've heard concerns that the Eclipse formatter rearranges comments. I think the current style avoids that problem.

### Upcoming Work

• Today's writeup: Exercise 5.
• Part 2 of the project is due Friday at 10:30 p.m. (No, I'm not updating the Web page.)

### Extra Credit

• Today's Town Hall at noon and 7:30 on Work/Life balance.
• One pride week activity.
• Math extra Thursday: Sphere Packing.
• CS Table Friday: Heartbleed.
• Women's Track and Field Friday at Simpson.
• Iowater project April 26 - Tag drains. Mail iowater@grinnell.edu for details.

## Remaining Questions from Heaps

• Given the index of an element, what are the indices of its left child, right child, and parent?
• Left child: 2i + 1
• Right child: 2(i+1)
• Parent: (i-1)/2, round down
• Why do we care about the indices of the children?
• We can actually store it in the array.
• For swapping down after removal
• Why do we care about the index of the parent?
• For swapping up after insertion

## Heap Sort

Repeatedly remove largest and shove at end.

• Each time we grab the largest and shove at the end is O(logN)
• The overall routine is O(NlogN)
• Why is this better than other NlogN sorting algorithms?
• Quicksort: Heap sort is predictable, Quicksort is not
• Merge sort: This sorts in place! Merge sort does not.
• Skip list sort: Heap sort is predictable. Skip list sort is not And uses lots of overhead.

• No.

## Lab

Writeup number 5!

Copyright (c) 2013-14 Samuel A. Rebelsky.

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit `http://creativecommons.org/licenses/by/3.0/` or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.