|
1 | 1 | # Project: 0x1B. C - Sorting algorithms & Big O
|
2 | 2 |
|
3 | | -## Resources |
| 3 | +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. |
4 | 4 |
|
5 | | -#### Read or watch: |
6 | | - |
7 | | -* [Sorting algorithm](https://intranet.alxswe.com/rltoken/-j5MKLBlzZAC2RfJ5DTBIg) |
8 | | -* [Big O notation](https://intranet.alxswe.com/rltoken/WRvrE2BaNVQFssHiUATTrw) |
9 | | -* [Sorting algorithms animations](https://intranet.alxswe.com/rltoken/ol0P7NbYVb5R31iOv4Q40A) |
10 | | -* [15 sorting algorithms in 6 minutes](https://intranet.alxswe.com/rltoken/_I0aEvhfJ66Xyob6dd9Utw) |
11 | | -* [CS50 Algorithms explanation in detail by David Malan](https://intranet.alxswe.com/rltoken/Ea93HeEYuNkOL7sGb6zzGg) |
12 | | -* [All about sorting algorithms](https://intranet.alxswe.com/rltoken/21X_eaj5RGcLIL9mZv2sqw) |
13 | 5 | ## Learning Objectives
|
14 | 6 |
|
15 | | -### General |
16 | | - |
17 | | -* At least four different sorting algorithms |
18 | | -* What is the Big O notation, and how to evaluate the time complexity of an algorithm |
19 | | -* How to select the best sorting algorithm for a given input |
20 | | -* What is a stable sorting algorithm |
21 | | -## Tasks |
22 | | - |
23 | | -| Task | File | |
24 | | -| ---- | ---- | |
25 | | -| 0. Bubble sort | [SOON](./) | |
26 | | -| 1. Insertion sort | [SOON](./) | |
27 | | -| 2. Selection sort | [SOON](./) | |
28 | | -| 3. Quick sort | [SOON](./) | |
29 | | -| 4. Shell sort - Knuth Sequence | [SOON](./) | |
30 | | -| 5. Cocktail shaker sort | [SOON](./) | |
31 | | -| 6. Counting sort | [SOON](./) | |
32 | | -| 7. Merge sort | [SOON](./) | |
33 | | -| 8. Heap sort | [SOON](./) | |
34 | | -| 9. Radix sort | [SOON](./) | |
35 | | -| 10. Bitonic sort | [SOON](./) | |
36 | | -| 11. Quick Sort - Hoare Partition scheme | [SOON](./) | |
37 | | -| 12. Dealer | [SOON](./) | |
| 7 | +- At the end of this project, you are expected to be able to explain to anyone, without the help of Google: |
| 8 | + - What is a sorting algorithm |
| 9 | + - What is the Big O notation, and how to evaluate the time complexity of an algorithm |
| 10 | + - How to select the best sorting algorithm for a given input |
| 11 | + - What is a stable sorting algorithm |
| 12 | + |
| 13 | +## Implemented Sorting Algorithms |
| 14 | + |
| 15 | +1. Bubble Sort - [0-bubble_sort.c](0-bubble_sort.c) |
| 16 | +2. Insertion Sort - [1-insertion_sort_list.c](1-insertion_sort_list.c) |
| 17 | +3. Selection Sort - [2-selection_sort.c](2-selection_sort.c) |
| 18 | +4. Quick Sort - [3-quick_sort.c](3-quick_sort.c) |
| 19 | +5. Merge Sort - [103-merge_sort.c](103-merge_sort.c) |
| 20 | +6. Heap Sort - [104-heap_sort.c](104-heap_sort.c) |
| 21 | + |
| 22 | +## Future Implementations |
| 23 | + |
| 24 | +1. Shell Sort |
| 25 | +2. Cocktail Shaker Sort |
| 26 | +3. Counting Sort |
| 27 | +4. Radix Sort |
| 28 | +5. Bitonic Sort |
| 29 | +6. Quick Sort (Hoare partition scheme) |
| 30 | +7. Deck of Cards Sort |
| 31 | + |
| 32 | +## Files |
| 33 | + |
| 34 | +- [sort.h](sort.h): Header file containing all function prototypes and the `listint_t` data structure. |
| 35 | +- [print_array.c](print_array.c): Function to print an array. |
| 36 | +- [print_list.c](print_list.c): Function to print a linked list. |
| 37 | +- `*-O`: Files containing the Big O notation for time complexity of each sorting algorithm. |
| 38 | + |
| 39 | +## Compilation |
| 40 | + |
| 41 | +All files should be compiled on Ubuntu 20.04 LTS using gcc with the following flags: |
| 42 | + |
| 43 | +```sh |
| 44 | +gcc -Wall -Werror -Wextra -pedantic -std=gnu89 |
| 45 | +``` |
| 46 | + |
| 47 | +## Usage |
| 48 | + |
| 49 | +```sh |
| 50 | +gcc -Wall -Werror -Wextra -pedantic -std=gnu89 [MAIN_FILE] [SORT_FILE] print_array.c -o [OUTPUT_NAME] |
| 51 | +./[OUTPUT_NAME] |
| 52 | +``` |
| 53 | + |
| 54 | +For example, to run Bubble Sort: |
| 55 | + |
| 56 | +```sh |
| 57 | +gcc -Wall -Werror -Wextra -pedantic -std=gnu89 0-main.c 0-bubble_sort.c print_array.c -o bubble |
| 58 | +./bubble |
| 59 | +``` |
| 60 | + |
| 61 | +## Data Structures |
| 62 | + |
| 63 | +The project uses the following data structure for doubly linked lists: |
| 64 | + |
| 65 | +```c |
| 66 | +typedef struct listint_s |
| 67 | +{ |
| 68 | + const int n; |
| 69 | + struct listint_s *prev; |
| 70 | + struct listint_s *next; |
| 71 | +} listint_t; |
| 72 | +``` |
| 73 | + |
| 74 | +## Big O Notation |
| 75 | + |
| 76 | +Each sorting algorithm includes a file with its time complexity in Big O notation: |
| 77 | + |
| 78 | +- Best case scenario |
| 79 | +- Average case scenario |
| 80 | +- Worst case scenario |
| 81 | + |
| 82 | +## Author |
| 83 | + |
| 84 | +- [Abdelrahman Mohamed](https://x.com/hackersa3edy/) |
| 85 | + |
| 86 | +## Acknowledgements |
38 | 87 |
|
| 88 | +This project was completed as part of the ALX Software Engineering curriculum. |
0 commit comments