Data Structures
Data Structures
FINAL EXAMINATION
Quick Sort
- QuickSort is a well-known sorting algorithm used in computer science and information
technology to put items in a data structure—usually an array or list—in a certain order. It
is a divide-and-conquer sorting algorithm that is effective and based on comparisons.
Advantages:
Efficiency
- Among the quickest sorting algorithms for big datasets, QuickSort has an average time
complexity of O(n log n).
- In practice, it performs better than a lot of other sorting algorithms, such as bubble sort
and insertion sort.
In-Place Sorting
- As an in-place sorting algorithm, QuickSort eliminates the need for extra RAM for
auxiliary data structures. It improves memory efficiency by sorting the array in place.
Cache Efficiency
- QuickSort often exhibits good cache performance because of its sequential and
localized access patterns during the partitioning phase.
Disadvantages:
Worst-Case Time Complexity
- In the worst-case scenario, where pivot selection continually results in imbalanced
partitions, QuickSort's temporal complexity is O(n^2). If the input array is sorted, or
almost sorted, this may occur.
Non-Stable Sort
- QuickSort is not a stable sorting algorithm, the sorted result may not contain equal
components in the original order.
Pivot Sensitivity
- The pivot that is selected can have an impact on QuickSort's efficiency. Inadequate
pivot decisions might result in less than ideal performance, particularly when dealing with
fixed or sorted datasets.
Merged Sort
- Another well-liked and effective sorting algorithm with a solid track record of
dependability is merge sort. The divide-and-conquer tactic is used to sort a list or array.
Disadvantages;
Additional Memory Requirement
- For the merging process, Merge Sort needs more RAM. This could be problematic in
settings where memory is a scarce resource. There are more intricate in-place Merge
Sort variants.
Slower on Small Datasets
- For small datasets, Merge Sort may be a little slower than other algorithms due to its
possible higher constant factors in time complexity. Simpler methods, such as insertion
sort, might be more effective for small arrays.
Not Adaptive
- The properties of the input data are not taken into account by Merge Sort. Regardless
of the original sequence of pieces, it works equally well or poorly, which may be
important to take into account in some situations.
Heap Sort
- Heap Sort is a comparison-based sorting method that builds a partially ordered binary
tree (heap) using a binary heap data structure, after which the elements are efficiently
sorted. Large datasets can benefit from its O(n log n) time complexity in all scenarios.
Disadvantages:
Not Stable
- The sorting algorithm known as heap sort is unstable. In the sorted output, equal
elements might not stay in the same order.
Less Cache-Friendly
- Heap Sort's memory access patterns are less cache-friendly than those of several
other algorithms, such as Merge Sort. Performance may suffer a little as a result,
particularly on systems with little cache.
Not Adaptive
- The properties of the input data are not taken into account by Heap Sort. It works
independent of the elements' original arrangement, either very effectively or very poorly.