Sei sulla pagina 1di 16

Comparison Of All Sorting

Algorithms

Presentation
By
G.Gopi Krishna Reddy
Sorting
• The Process of rearranging the elements
so that they are in ascending order or
descending order is called sorting.
• Example:
arranging of numbers, student records.
very essential for searching the
dictionaries, telephone directories.
Properties
The two Main properties of sorting techniques are:

• Stable: If the sorting algorithm preserves


the relative order of any two equal elements,then
the sorting algorithm is stable.

• In Place: If an algorithm does not require an


extra memory space except for few memory
units,then the algorithm is said to be in place.
Sorting Algorithms
Various sorting algorithms are

Bubble Sort
Selection Sort
Insertion Sort
Quick Sort
Merge Sort
Bubble Sort
• This is one of the most simplest sorting
technique and most straight forward
method of sorting.
• In this sorting technique, the adjacent
elements in the list are compared and
exchanged if they are out of order.
• This is also called as Sinking Sort
Time Complexity(Bubble sort)
• The time complexity of bubble sort in all
three cases (best,average & worst)is

T(n) = θ(n^2)

Which is not efficient compare to other


sorting techniques.
Selection Sort
• In this technique first we find the smallest item in
the list and we exchange it with the first item.
• Next,obtain the second smallest item in the list &
exchange it with the second element and so on.
• Since, the next least item is selected and
exchanged appropriately so that elements are
finally sorted ,this technique is called
Selection Sort
Time Complexity(Selection sort)
• The time complexity of selection sort in all
three cases (best,average&worst) is
T(n) = θ(n^2)

Which is not efficient compare to other


sorting techniques.
Insertion Sort
• In this technique the given list is divided into two
parts:sorted part(left) &unsorted part(right).
• The unsorted elements can be placed any of the
positions in the sorted part so that elements
towards left of boundary are sorted.
• As each item is inserted towards the sorted left
part, the boundary moves to the right decreasing
the unsorted list.
• Finally,once the boundary moves to the right
most position,the elements towards the left of
boundary represent the sorted list.
Time Complexity(Insertion sort)
• The Time complexity of insertion sort is:
Worst case: T(n) = O(n^2)

Average case: T(n) = θ(n^2)

Best case: T(n) = Ω(n)


Quick sort
• In quick sort, partition the array into two
parts such that elements towards left of key
element are less than key element and
elements towards right of key element are
greater than key element.
• Sort the left part of the array recursively.
• Sort the right part of the array recursively.
Time Complexity(Quick sort)
• The time complexity of Quick sort is:
Worst case: T(n) = O(n log n)

Average case: T(n) = θ(nlog2n)

Best case:
T(n) = O(n log n)
Merge sort
• In merge sort, a given array of elements is
divided into two parts.
• The left part of the array as well as the right part
of the array is sorted recursively.
• Later, the sorted left part and the sorted right part
are finally merged into a single sorted vector.
• The process of merging of two sorted vectors into
a single sorted vector is called simple merge.
Time complexity(Merge sort)
• The time complexity of Merge sort in all
three cases (best,average&worst) is:

T(n) = θ(nlog2n)
Conclusion
• By comparing all the sorting techniques
Merge sort time complexity is less in all
three cases (time consuming is less).
• So, Merge sort is the most efficient
technique when compare to all other
sorting techniques.
THANK YOU