Friday, 28 February 2014

Heap Sort

Heap Sort
A large area of memory from which the programmer can allocate blocks as needed, and deal locate them (or allow them to be garbage collected) when no longer needed
A balanced, left-justified binary tree in which no node has a value greater than the value in its parent

Class
Data structure
 total,  auxiliary

Example
Here’s a sample binary tree after it has been heapified

Algorithm
       MAXHEAPIFY(A, i)
       1. l←LEFT(i)
       2. r←RIGHT(i)
       3. ifl ≤ heapsize[A] and A[l] > A[i]
       4. then largest←l
       5. else largest←i
       6. ifr ≤ heapsize[A] and a[r] > A[largest]
       7. then largest←r
       8. iflargest≠i
       9. then exchange A[i] A[largest]

       10. MAXHEAPIFY (A, largest)

No comments:

Post a Comment