bebetterthinker / sorting_algorithms

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

0x1B. C - Sorting algorithms & Big O

Foundations - Low-level programming & Algorithm ― Data structures and Algorithms

Data Structure and Functions

  • For this project you are given the following print_array, and print_list functions:

the following task that i solved

0. Bubble sort mandatory

Write a function that sorts an array of integers in ascending order using the

  • Prototype: void bubble_sort(int *array, size_t size);
  • You’re expected to print the array after each time you swap two elements (See example below)

Write in the file 0-O, the big O notations of the time complexity of the Bubble sort algorithm, with 1 notation per line:

  • in the best case
  • in the average case
  • in the worst case
#### 1. Insertion sort  mandatory




Write a function that sorts a doubly linked list of integers in ascending order using the  

-   Prototype:  `void insertion_sort_list(listint_t **list);`
-   You are not allowed to modify the integer  `n`  of a node. You have to swap the nodes themselves.
-   You’re expected to print the  `list`  after each time you swap two elements (See example below)

Write in the file  `1-O`, the big O notations of the time complexity of the Insertion sort algorithm, with 1 notation per line:

-   in the best case
-   in the average case
-   in the worst case

2. Selection sort mandatory

Write a function that sorts an array of integers in ascending order using the

  • Prototype: void selection_sort(int *array, size_t size);
  • You’re expected to print the array after each time you swap two elements (See example below)

Write in the file 2-O, the big O notations of the time complexity of the Selection sort algorithm, with 1 notation per line:

  • in the best case
  • in the average case
  • in the worst case

#### 3. Quick sort  mandatory

Write a function that sorts an array of integers in ascending order using the  [Quick sort]
-   Prototype:  `void quick_sort(int *array, size_t size);`
-   You must implement the  `Lomuto`  partition scheme.
-   The pivot should always be the last element of the partition being sorted.
-   You’re expected to print the  `array`  after each time you swap two elements (See example below)

Write in the file  `3-O`, the big O notations of the time complexity of the Quick sort algorithm, with 1 notation per line:

-   in the best case
-   in the average case
-   in the worst case

About


Languages

Language:C 100.0%