This project is a comprehensive study and implementation of various sorting algorithms in C. It aims to provide a deep understanding of different sorting techniques, their time complexities (Big O notation), and how to select the most efficient algorithm for a given input.
- At the end of this project, you are expected to be able to explain to anyone, without the help of Google:
- What is a sorting algorithm
- What is the Big O notation, and how to evaluate the time complexity of an algorithm
- How to select the best sorting algorithm for a given input
- What is a stable sorting algorithm
- Bubble Sort - 0-bubble_sort.c
- Insertion Sort - 1-insertion_sort_list.c
- Selection Sort - 2-selection_sort.c
- Quick Sort - 3-quick_sort.c
- Merge Sort - 103-merge_sort.c
- Heap Sort - 104-heap_sort.c
- Shell Sort
- Cocktail Shaker Sort
- Counting Sort
- Radix Sort
- Bitonic Sort
- Quick Sort (Hoare partition scheme)
- Deck of Cards Sort
- sort.h: Header file containing all function prototypes and the
listint_t
data structure. - print_array.c: Function to print an array.
- print_list.c: Function to print a linked list.
*-O
: Files containing the Big O notation for time complexity of each sorting algorithm.
All files should be compiled on Ubuntu 20.04 LTS using gcc with the following flags:
gcc -Wall -Werror -Wextra -pedantic -std=gnu89
gcc -Wall -Werror -Wextra -pedantic -std=gnu89 [MAIN_FILE] [SORT_FILE] print_array.c -o [OUTPUT_NAME]
./[OUTPUT_NAME]
For example, to run Bubble Sort:
gcc -Wall -Werror -Wextra -pedantic -std=gnu89 0-main.c 0-bubble_sort.c print_array.c -o bubble
./bubble
The project uses the following data structure for doubly linked lists:
typedef struct listint_s
{
const int n;
struct listint_s *prev;
struct listint_s *next;
} listint_t;
Each sorting algorithm includes a file with its time complexity in Big O notation:
- Best case scenario
- Average case scenario
- Worst case scenario
This project was completed as part of the ALX Software Engineering curriculum.