CHAPTER 4 - ALGORITHMS IN C -SORTING
CHAPTER 4 - ALGORITHMS IN C -SORTING
C/C++
D ATA S T R U C T U R E a n d A L G O R I T H M S
⚬ Sorting?
⚬ Sorting is a very classic problem of reordering items (that can
be compared, e.g., integers, floating-point numbers, strings, etc)
of an array (or a list) in a certain order (increasing, non-
decreasing (increasing or flat).
⚬ Sorting algorithms are a set of techniques used to rearrange
the elements of a list or array into a particular order.
⚬ There are numerous sorting algorithms, each with its own
advantages and disadvantages in terms of efficiency, ease of
implementation, and suitability for different types of data and
problem sizes.
4 . 3 S O RT I N G A L G O R I T H M S :
⚬ Sorting algorithms:
⚬ Bubble Sort (Time complexity: O(n^2)): This brute-force
algorithm repeatedly steps through the list, compares adjacent
elements, and swaps them if they are in the wrong order.
⚬ Selection Sort (Time complexity: O(n^2)): Another brute-force
algorithms: divides the list into two parts: the sub-list of items
already sorted and the sub-list of items to be sorted.
⚬ Insertion Sort (Time complexity: O(n^2)): Insertion sort builds
the sorted list one element at a time by repeatedly taking the next
element from the unsorted part of the array and inserting it into its
correct position in the sorted part.
4 . 3 S O RT I N G A L G O R I T H M S :