HeapSort

Heap Sort

Definition one of sort array data structure based on binary tree insert data into binary tree and print out from the tree Algorithm steps insert data into binary tree The data sorted as binary tree print Java code public static void heapSort(int arr[]) { int n = arr.length; // Build heap (rearrange array) for (int i = n / 2 - 1; i >= 0; i--) heapTree(arr, n, i); // One by one extract an element from heap for (int i = n - 1; i > 0; i--) { // Move current root to end int temp = arr[0]; arr[0] = arr[i]; arr[i] = temp; // call max heapify on the reduced heap heapTree(arr, i, 0); } } // To heapify a subtree rooted with node i which is // an index in arr[].