SUNY Geneseo Department of Computer Science
{Date}
CSci 240, Spring 2007
Prof. Doug Baldwin
SOFIs
Final exam
Problem Set 14 due today
Finish section 14.4, from "Insertion" (page 500) through end (page 503)
Flesh out the bottom-up insertion algorithm in terms of a tree in an array
// in class MaxHeap<E extends Comparable<...> >
private E[] elements // 0-origin
private int n
insertBottomUp( v )
elements[n] = v
n = n + 1
i = n - 1
while ( (i-1)/2 >= 0 && elements[i] > elements[ (i-1)/2 ] )
swap( i, (i-1)/2 )
i = (i-1)/2
void swap( int a, int b )
E x = elements[a]
elements[a] = elements[b]
elements[b] = x
Swap and object representation
Finish heap insertion and deletion algorithms.
Mini-assignment above re sifting down.