XaaS
sorting techniques

Sorting techniques in data structures

Sorting techniques is the process to identify element according to the size of the data. In addition, Data Structure is the collection and organisation of data to provide logical relationship between data. Moreover, there are many applications of sorting. For instance, we use sorting in contact applications in our mobile applications.

sorting techniques

Let us take a look at some of the sorting techniques.

  1. Bubble Sort
  2. Selection Sort
  3. Insertion Sort
  4. Merge Sort
  5. Quick Sort
  6. Heap Sort
  7. Shell Sort

Bubble Sort (First Sorting Technique)

Firstly, in bubble sort, each and every element compares itself with the next element starting from the first position. Secondly, this kind of sort applies to small amount of data. Moreover, in computer system, memory saving procedure uses bubble sort.

For instance, we have a data like 50, 40, 10, 15. Here 50 will be compared with 40 then 10 and lastly 15. And outcome will be 10, 15, 40 and 50 after some iterations.

Selection Sort

Firstly, in selection sort, we find the smallest key value and first element replaces itself with the smallest key. And second element with second smallest key and so on.

For instance, values are 45, 55, 75, 15, 65.

  • First Iteration: 15, 55, 75, 45, 65.
  • Second Iteration: 15, 45, 75, 55, 65.
  • Third Iteration: 15, 45, 55, 75, 65.
  • Fourth Iteration: 15, 45, 55, 65, 75.
  • Hence, result is: 15, 45, 55, 65, 75.

Insertion Sort

In Insertion Sort, we consider the first position as sorted and then compare every element with the sorted element.

For instance, data is 6, 5, 3, 1,8.

  • First Iteration: 5, 6, 3, 1, 8.
  • Second Iteration: 3, 5, 6, 1, 8
  • Third Iteration: 1, 3, 5, 6, 8.

Merge Sort

Merge Sort is useful when we have a large amount of data. This sorting technique uses divide and conquer strategy. Firstly, it divides the data, sorts the element and then combines the data.

Secondly, it is one of the efficient sorting algorithm.

Quick Sort

In quick sort, there is a pivot value along with i and j. For instance, we have an array of size 8, here the first value will be the pivot value. Moreover, Iteration of i starts from the beginning of array and iteration of j starts from the end of array.

Secondly, values for i and jth element is compared , if i<j then we exchange the values.

Time Complexity Table for Sorting techniques

Sorting TechniqueBest CaseAverage CaseWorst Case
Bubble SortO(n)O(n2)O(n2)
Selection SortO(n2)O(n2)O(n2)
Insertion SortO(n)O(n2)O(n2)
Merge SortO(nlogn)O( nlogn)O( nlogn)
Quick SortnlognnlognO(n2)
Heap SortO( nlogn)O(nlogn)O(nlogn)

Summary

In conclusion, we have learnt about the different sorting techniques in data structures. Moreover, we have seen the time complexities of different sorts.

About the author

Drishti Patel

View all posts
0 0 votes
Article Rating
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
trackback

[…] Uses heap data structure […]