# Algorithms

In the updated version of the maTH library, we can also use sorting (currently, maybe more diverse in future) algorithms, so there is no need to write your own. It supports the following algorithms:

<table data-full-width="true"><thead><tr><th>Algorithm</th><th>O notation (best, average, worst case)</th><th>Source</th></tr></thead><tbody><tr><td>Bubble sort</td><td><span class="math">O(n^2)</span>, <span class="math">O(n^2)</span>, <span class="math">O(n^2)</span></td><td><a data-mention href="algorithms/bubble-sort">bubble-sort</a></td></tr><tr><td>Insertion sort</td><td><span class="math">O(n)</span>, <span class="math">O(n^2)</span>, <span class="math">O(n^2)</span></td><td><a data-mention href="algorithms/insertion-sort">insertion-sort</a></td></tr><tr><td>Selection sort</td><td><span class="math">O(n^2)</span>, <span class="math">O(n^2)</span>, <span class="math">O(n^2)</span></td><td><a data-mention href="algorithms/selection-sort">selection-sort</a></td></tr><tr><td>Merge sort</td><td><span class="math">O(n log n)</span>, <span class="math">O(n log n)</span>, <span class="math">O(n log n)</span></td><td><a data-mention href="algorithms/merge-sort">merge-sort</a></td></tr><tr><td>Quicksort</td><td><span class="math">O(n log n)</span>, <span class="math">O(n log n)</span>, <span class="math">O(n^2)</span></td><td><a data-mention href="algorithms/quicksort">quicksort</a></td></tr><tr><td>Heap sort</td><td><span class="math">O(n log n)</span>, <span class="math">O(n log n)</span>, <span class="math">O(n log n)</span></td><td><a data-mention href="algorithms/heap-sort">heap-sort</a></td></tr><tr><td>Count sort</td><td><span class="math">O(n + k)</span>, <span class="math">O(n + k)</span>, <span class="math">O(n + k)</span></td><td><a data-mention href="algorithms/count-sort">count-sort</a></td></tr><tr><td>Bucket sort</td><td><span class="math">O(n + k)</span>, <span class="math">O(n)</span>, <span class="math">O(n^2)</span></td><td><a data-mention href="algorithms/bucket-sort">bucket-sort</a></td></tr><tr><td>Radix sort</td><td><span class="math">O(nk)</span>, <span class="math">O(nk)</span>, <span class="math">O(nk)</span></td><td><a data-mention href="algorithms/radix-sort">radix-sort</a></td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://math-5.gitbook.io/math/reference/algorithms.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
