If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions.
In this post, we will see about Sorting algorithms in java.
A Sorting algorithm is an algorithm which puts collection of elements in specific order.
For example:
You want to sort list of numbers into ascending order or list of names into lexicographical order.
There are lots of questions being asked on sorting algorithms about its implementation, time complexity in data structure and algorithms interviews.It is very essential to understand pros and cons for all sorting algorithm before you go for algorithm interview.
Table of Contents
Java Sorting Algorithms
Here is list of Sorting algorithms.
1. Bubble sort
Implementation of bubble sort
Time Complexity:
Best case: O(n)
Average case: O(n^2)
Worst case: O(n^2)
2. Insertion sort
Implementation of Insertion sort
Time Complexity:
Best case: O(n)
Average case: O(n^2)
Worst case: O(n^2)
3. Selection sort
Implementation of Selection Sort
Time Complexity:
Best case : O(N^2)
Average case : O(N^2)
Worst case : O(N^2)
4. Heap sort
Time Complexity:
Best case : O(nlogn)
Average case : O(nlogn)
Worst case : O(nlogn)
5. Quick Sort
Time Complexity:
Best case : O(nlogn)
Average case : O(nlogn)
Worst case : O(n^2)
6. Merge sort
Time Complexity:
Best case : O(nlogn)
Average case : O(nlogn)
Worst case : O(nlogn)
7. Shell Sort
Time Complexity:
Best case : O(nlogn)
Average case : O(n(logn)^2)
Worst case : O(n(logn)^2)
8. Counting Sort
Implementation of Counting Sort
Time Complexity:
Best case : O(n+k)
Average case : O(n+k)
Worst case : O(n+k)
9. Bucket Sort
Time Complexity:
Best case : O(n+k)
Average case : O(n+k)
Worst case : O(n^2)
10. Radix sort
Time Complexity:
Best case : O(nk)
Average case : O(nk)
Worst case : O(nk)
Github Source code:
That’s all about Sorting algorithms in java.