6.5-6 Each exchange operation on line 5 of HEAP-INCREASE-KEY typically requires three assignments. Show how to use the idea of the inner loop of INSERTIONSORT to reduce the three assignments down to just one assignment.
MAX-HEAP-INSERT-KEY(A,i,key)
If i > key
error "invalid key value"
a[i] = key
while( i > 1 and a[parent(i)] < a[i])
a[i] = a[parent(i)]
i = parent(i);
a[i] = key;
No comments:
Post a Comment