Question
A sorting algorithm is considered "stable" if it maintains the relative order of records with equal keys. Which of the following algorithms is generally stable?
Solution
Merge Sort is a stable sorting algorithm because it can be implemented to preserve the relative order of equal elements during the merging process. Quick Sort, Heap Sort, and Selection Sort are typically unstable as they might swap equal elements, changing their original relative order. Shell Sort is also generally unstable.
More Algorithms Questions
- Which sorting algorithm is not stable by default?
- Which page replacement algorithm replaces the page that will not be used for the longest period of time in the future?Β Β
- In a binary search algorithm, what is the time complexity of searching an element in a sorted array of size n?Β Β Β
- For a comparison-based sorting algorithm, which lower bound applies to the worst-case number of comparisons?
- Output of below code public class Prg { public static void main(String args[]){  ...
- What HTTP method is primarily used to retrieve data from a server in a REST API?
- In networking, what is the key difference between IPv4 and IPv6?
- What is the primary function of a firewall in network security?
- Which sorting algorithm uses the 'Divide and Conquer' strategy and what is its recurrence relation?
- In the context of Data Modelling and Analytics, which technique is most suitable for identifying the underlying patterns in high-dimensional data without e...