0% found this document useful (0 votes)
27 views1 page

Sorting Algorithms Interview Table

The document provides a summary of various sorting algorithms, detailing their average, best, and worst-case time complexities, space requirements, and stability. It highlights key algorithms like Bubble Sort, Insertion Sort, Merge Sort, Quick Sort, and Selection Sort, along with their preferred use cases and characteristics. Additionally, it discusses the ideal properties of a sorting algorithm and mentions Java's built-in sorting methods.

Uploaded by

rajsugamani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views1 page

Sorting Algorithms Interview Table

The document provides a summary of various sorting algorithms, detailing their average, best, and worst-case time complexities, space requirements, and stability. It highlights key algorithms like Bubble Sort, Insertion Sort, Merge Sort, Quick Sort, and Selection Sort, along with their preferred use cases and characteristics. Additionally, it discusses the ideal properties of a sorting algorithm and mentions Java's built-in sorting methods.

Uploaded by

rajsugamani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Sorting Algorithms Summary (Interview Preparation)

Name Time Avg Best Case Worst Case Space Stable Technique

Bubble Sort O(n²) O(n) O(n²) O(1) Yes Comparison-based

Insertion Sort O(n²) O(n) O(n²) O(1) Yes Comparison-based

Selection Sort O(n²) O(n²) O(n²) O(1) No Comparison-based

Merge Sort O(n log n) O(n log n) O(n log n) O(n) Yes Divide & Conquer &
Comparision-based

Quick Sort O(n log n) O(n log n) O(n²) O(log n) No Divide & Conquer &
Comparision-based
Heap Sort O(n log n) O(n log n) O(n log n) O(1) No Heap-based &
Comparision-based

Which algorithm always takes O(n²) time regardless of input? Selection Sort

Which sort algorithm works best on mostly sorted data?


Answer: For mostly sorted data, Insertion Sort typically works best. It’s efficient when elements are mostly in order
because it only needs to make small adjustments to place each element in its correct position, making it faster than other
sorting algorithms like Quick Sort or Merge Sort.

Why is Merge sort preferred over Quick Sort for sorting linked lists?
Answer: Merge Sort is preferred for sorting linked lists because its divide-and-conquer approach easily divides the list
into halves and merges them efficiently without requiring random access, which is difficult in linked lists. Quick Sort’s
reliance on random access and potential worst-case time complexity makes it less suitable for linked lists.

What is Stability in sorting algorithm and why it is important?


Answer: Stability in sorting algorithms means that the relative order of equal elements remains unchanged after sorting.
Stable sorting algorithms ensure that equal elements maintain their original positions in the sorted sequence. Some of
the stable sorting algorithms are: Bubble Sort, Insertion Sort, Merge Sort and Counting Sort.

Which sort algorithm works best on mostly sorted data?


Answer: For mostly sorted data, Insertion Sort typically works best. It’s efficient when elements are mostly in order
because it only needs to make small adjustments to place each element in its correct position, making it faster than other
sorting algorithms like Quick Sort or Merge Sort.

What are the different types of sorting algorithms?


Answer: There are two types of Sorting algorithms: Comparison based sorting algorithms and non-comparison-based
sorting algorithms. Comparison based sorting algorithms include Bubble Sort, Selection Sort, Insertion Sort, Merge Sort,
Quick Sort, Heap Sort, etc. and non-comparison-based sorting algorithms include Radix Sort, Counting Sort and Bucket
Sort.

Explain what is ideal Sorting Algorithm?


Answer: The Ideal Sorting Algorithm would have the following properties:
Stable: Equal keys are not reordered.
Operates in place: Requires O(1) extra space.
Worst-case O(n log n) key comparisons: Guaranteed to perform no more than O(n log n) key
comparisons in the worst case.
Adaptive: Speeds up to O(n) when the data is nearly sorted or when there are few unique keys.

Which of these comparison-based sorting algorithms has the lowest upper bound on time complexity?
Merge Sort & Heap Sort guaranteed O(n log n) time in all cases

Which sorting algorithm performs least number of swaps? Selection Sort

Built-in Sorting Method of Java : Arrays.sort() & Collections.sort() Uses Which Algorithms?
Primitive Data Type - Dual Pivot sorting Algorithm
Objects(User defined or Collections) - Tim Sorting (Combination of Merge and Insertion Sort)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy