Sorting Flashcards
is an efficient sorting technique based on the >heap data structure.
heap sort
is a nearly-complete binary tree where the parent node could either be minimum
or maximum.
The
heap
The heap with minimum root node is called ______- and the root node
with maximum root node is called __________
min heap
max heap
Build a binary heap from the input array.
Build heap
Extract the maximum element
from the heap and add it to the sorted region.
extract maximum
Heapify the remaining elements of the heap
to maintain the heap property.
Heapify
The time complexity of heap sort is
O(n log n)
Heap sort is a __________
sorting algorithm, meaning it preserves the relative order of
elements with equal keys.
stable
can be used to efficiently implement priority queues because
they allow us to insert, delete, and find the element with the highest priority in
logarithmic time.
Heap operations
a process of creating a heap from an array.
heapify
process to insert an element in existing heap time complexity
O(log N).
Insertion:
deleting the top element of the heap or the highest priority
element, and then organizing the heap and returning the element with time
complexity O(log N).
Deletion:
to check or find the most prior element in the heap, (max or min
element for max and min heap).
Peek:
The most popular kind of heap sort, arranges the elements of
the array in ascending order.
Max heap sort:
With a _____________, the array is arranged in ascending order.
Min heap sort:
a simple sorting algorithm that builds the final
sorted array one item at a time by comparisons.
insertion sort
It is much less
efficient on large lists than more advanced algorithms such as
quicksort, heapsort, or merge sort.
insertion sort
t iterates, consuming one input element each repetition,
and grows a sorted output list. At each iteration, it
removes one element from the input data, finds the location it
belongs within the sorted list, and inserts it there
insertion sort
Insertion sort is also ___________-, i.e., it
is appropriate for data sets that are ___________. Lastly,
it is an___________sorting algorithm and a _____________ sorting algorithm.
Insertion sort is also adaptive in nature, i.e., it
is appropriate for data sets that are already partially sorted. Lastly,
it is an in-place sorting algorithm and a stable sorting algorithm.
insertion sort best average, worst case time complexity
O(n)
O(n^2)
O(n^2)
It is efficient for small data sets or nearly sorted
data
insertion sort
is adaptive in nature, i.e. it is
appropriate for data sets that are already
partially sorted
Insertion sort
insertion sort memory space
constant amount of additional memory space