Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

C Implementation of Various Sorting Algorithms

C Implementation of Various Sorting Algorithms

This is a simple C implementation of various sorting algorithms such as Bubble Sort, Insertion Sort, Selection Sort and Shell Sort.

Bubble Sort

Bubble sort, is a simple comparison-based sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. The pass through the list is repeated until the list is sorted.

Complexity:

Worst complexity: n^2
Best complexity: n

Insertion Sort

Insertion sort is a simple sorting algorithm that builds the final list one item at a time. This is an in-place comparison-based sorting algorithm. It is much less efficient on large lists than more advanced algorithms such as quick sort, heap sort, or merge sort.

Complexity:

Worst complexity: n^2
Best complexity: n^2

Selection Sort

Selection sort is an in-place comparison-based algorithm in which the list is divided into two parts, the sorted part at the left end and the unsorted part at the right end. Initially, the sorted part is empty and the unsorted part is the entire list.

Complexity:

Worst complexity: n^2
Best complexity: n^2

Shell Sort

Shell Sort Algorithm, also known as Shell sort or Shell’s method, is an in-place comparison sorting algorithm. It can be seen as either a generalization of sorting by exchange or sorting by insertion.

Complexity:

Beginning C++23
Kickstart your coding journey with Beginning C++23 – the ultimate guide to mastering the latest in modern C++ programming!
View on Amazon

Average complexity: n*log(n)^2 or n^(3/2)
Best complexity: n

About The Author

M. Saqib

Saqib is Master-level Senior Software Engineer with over 14 years of experience in designing and developing large-scale software and web applications. He has more than eight years experience of leading software development teams. Saqib provides consultancy to develop software systems and web services for Fortune 500 companies. He has hands-on experience in C/C++ Java, JavaScript, PHP and .NET Technologies. Saqib owns and write contents on mycplus.com since 2004.