In sorted array, elements are sorted in numerical, alphabetical, or by some other order and stored at contiguous memory locations. | A heap is almost complete binary tree, In case of max heap, if p is the parent and c is its child, then the value of p is greater than or equal to the value of c and in min heap if p is the parent and c is its child, then the value p is less than or equal to the value of c. |
A sorted array can act as heap when using array based heap implementation. | Heap may or may not be a sorted array when using array based heap implementation. |
For a given set of integers, there can be two arrangements (i.e. ascending or descending) possible after sorting . |
For a given set of n integers, multiple possible heaps (max or min) can be formed.
Refer this article for more details
|
Here the next element address can be accessed by incrementing the index of current element. | Here the left child index can be accessed by calculating 2×r and right element index can be accessed by calculating 2×r+1, where r is the index of root and array is 1 index based. |
Searching can be performed in O(log n) time in sorted array by using binary search. | Heap is not optimal for searching operation but searching can be performed in O(n) complexity. |
Heap sort can be used for sorting an array, but for this first heap is build with array of n integers and then heap sort is applied. Here O(n) time complexity is needed for building heap and O(n log n) is required for removing n (min or max) element from heap and placing at the end of array and decreasing the size of array). | Heap sort which is applied on heaps (min or max) and it is in-place sorting algorithm for performing sorting in O(n log n) time complexity. |
Sorting an array requires O(n log n) complexity which is best time complexity for sorting an array of n items in comparison based sorting algorithm. | Building heap takes O(n) time complexity. |
Sorted array are used for performing efficient searching (i.e. binary search), SJFS scheduling algorithm and in the organizations where data is needed in sorted order etc. | The heaps are used in heap sort, priority queue, graph algorithms and K way merge etc. |