File tree Expand file tree Collapse file tree 4 files changed +14
-7
lines changed
Expand file tree Collapse file tree 4 files changed +14
-7
lines changed Original file line number Diff line number Diff line change 3838#include "typedefs.h"
3939
4040/**
41- * @brief Sort elements using bubble sort algorithm.
41+ * @brief Sort elements using bubble sort algorithm. It compares the adjacent elements and swaps them
42+ * if they are in the wrong order. It is done repeatedly until all elements are sorted.
43+ * Time complexity: O(N^2)
4244 *
4345 * @param[in/out] *buffer Pointer to the buffer that contains elements that will be sorted.
4446 * @param[in] number_of_elements Number of elements in the buffer.
Original file line number Diff line number Diff line change 3838#include "typedefs.h"
3939
4040/**
41- * @brief Sort elements using heap sort algorithm.
41+ * @brief Sort elements using heap sort algorithm. It uses heapify to convert array into max heap.
42+ * It deletes the root node of the max heap (one by one) and replaces it with the last node. After that,
43+ * heapify is done again. Whole process is repeated while heap size is greater than 1.
44+ * Time complexity: O(N log N)
4245 *
4346 * @param[in/out] *buffer Pointer to the buffer that contains elements that will be sorted.
4447 * @param[in] number_of_elements Number of elements in the buffer.
Original file line number Diff line number Diff line change 4040#define MAX_ELEMENT_SIZE (64)
4141
4242/**
43- * @brief Sort elements using insertion sort algorithm. Insertion sort algorithm is a simple
44- * sorting algorithm that has O(N^2) time complexity. It is efficient on smaller lists, and
45- * much less efficient on large lists.
43+ * @brief Sort elements using insertion sort algorithm. Divide given list into sorted and unsorted part
44+ * (first element is considered sorted). Iterate through each element in the unsorted part. Pick one
45+ * element at a time, and insert it into correct position in the sorted part. It is efficient on smaller
46+ * lists, and much less efficient on large lists.
47+ * Time complexity: O(N^2)
4648 *
4749 * NOTE: implemented that the max element size is 64 B. If element size is larger, then
4850 * MAX_ELEMENT_SIZE macro must be updated.
Original file line number Diff line number Diff line change 3838#include "typedefs.h"
3939
4040/**
41- * @brief Sort elements using selection sort algorithm. Selection sort algorithm is an in-place
42- * comparison sorting algorithm that has O(N^2) time complexity. It divides the input array into
41+ * @brief Sort elements using selection sort algorithm. It divides the input array into
4342 * two parts, sorted sub-array of items which is built up from left to right and unsorted items
4443 * that occupies the rest of the array. The sorted sub-array is empty and the unsorted sub-array
4544 * is the entire input array. The algorithm proceeds by finding the smallest element in the
4645 * unsorted sub-array, swapping it with the leftmost unsorted element (putting it in sorted order),
4746 * and moving the sub-array boundaries one element to the right.
47+ * Time complexity: O(N^2)
4848 *
4949 * @param[in/out] *buffer Pointer to the buffer that contains elements that will be sorted.
5050 * @param[in] number_of_elements Number of elements in the buffer.
You can’t perform that action at this time.
0 commit comments