notes110

notes110 - CS 251 notes for week of 2-11 2-11 Heap Sort of...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 251 notes for week of 2-11 2-11 Heap Sort of an Array use the same array to store the sequence to sort and the heap initially all the array is used to store the unsorted sequence (the heap is empty) heap || 3 | 7 | 5 | 6 | 1 | sequence heap | 3 || 7 | 5 | 6 | 1 | sequence heap | 7 | 3 || 5 | 6 | 1 | sequence heap | 7 | 3 | 5 || 6 | 1 | sequence heap | 7 | 6 | 5 | 3 || 1 | sequence heap | 7 | 6 | 5 | 3 | 1 || sequence 1 st phase – construct a heap from left to right o the heap needs to be an inverted heap o in phase 2 the values are from highest to lowest the complexity of phase 1 is O(nlogn) – the first n is the number of elements and the second is the height of the tree Phase 2 o from right to left remove the maximum element in the heap and place it at the end of the heap o swap the maximum element and the last element in the heap Heap implementation In an array in C, C++, and Java the index starts at 0, thus we need to subtract one from the position to get the index
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/02/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue.

Page1 / 3

notes110 - CS 251 notes for week of 2-11 2-11 Heap Sort of...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online