# Space and time complexity

### Time complexity

Time complexity describes how much time an algorithm needs to be complete. The time complexity is usually expressed using the following notations:

* Worst case → Big O (O) → `O(n)`
* Best case → Big Ω (Omega) -> `Ω(n)`
* Average case → Big Θ (Theta) -> `Θ(n)`

### Space complexity

Space complexity described how much space or memory an algorithm needs to be complete. The space complexity is usually expressed using the following notation:

* Worst case → Big O (O) → `O(n)`

#### Time and space complexity of search algorithms

| Search algorithm                                                                                                                                                                                                         | Time / Big-O     | Time / Big-Ω | Time / Big-Θ | Space / Big-O |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------- | ------------ | ------------ | ------------- |
| [Binary Search](https://nielslange.gitbook.io/developer-toolbox/algorithms/search-algorithms/binary-search)                                                                                                              | `O(log n)`       | `Ω(1)`       | `Θ(log n)`   | `O(1)`        |
| [Breadth First Search](https://nielslange.gitbook.io/developer-toolbox/algorithms/search-algorithms/breadth-first-search)                                                                                                | `O(\|V\|+\|E\|)` |              |              | `O(\|V\|)`    |
| [Depth First Search](https://nielslange.gitbook.io/developer-toolbox/algorithms/search-algorithms/depth-first-search)                                                                                                    | `O(\|V\|+\|E\|)` |              |              | `O(\|V\|)`    |
| [Exponential Sear](https://nielslange.gitbook.io/developer-toolbox/algorithms/search-algorithms/exponential-search)[ch](https://nielslange.gitbook.io/developer-toolbox/algorithms/search-algorithms/exponential-search) | `O(log n)`       | `Ω(1)`       | `Θ(log n)`   | `O(1)`        |
| [Fibonacci Search](https://nielslange.gitbook.io/developer-toolbox/algorithms/search-algorithms/fibonacci-search)                                                                                                        | `O(log n)`       | `Ω(1)`       | `Θ(log n)`   | `O(1)`        |
| [Interpolation Search](https://nielslange.gitbook.io/developer-toolbox/algorithms/search-algorithms/interpolation-search)                                                                                                | `O(log log n)`   |              |              |               |
| [Jump Search](https://nielslange.gitbook.io/developer-toolbox/algorithms/search-algorithms/jump-search)                                                                                                                  | `O(sqrt(n))`     |              |              | `O(1)`        |
| [Linear Search](https://codenex.wordpress.com/2021/01/24/developer-toolbox-%E2%86%92-linear-search/)                                                                                                                     | `O(n)`           | `Ω(1)`       | `Θ(n/2)`     | `O(1)`        |
| [Sublist Search](https://nielslange.gitbook.io/developer-toolbox/algorithms/search-algorithms/sublist-search)                                                                                                            | `O(m*n)`         |              |              |               |

### Links

* [https://www.educative.io/edpresso/time-complexity-vs-space-complexity](https://href.li/?https://www.educative.io/edpresso/time-complexity-vs-space-complexity)
* [https://levelup.gitconnected.com/time-and-space-complexity-725dcba31902](https://href.li/?https://levelup.gitconnected.com/time-and-space-complexity-725dcba31902)
* [https://en.wikipedia.org/wiki/Linear\_search](https://href.li/?https://en.wikipedia.org/wiki/Linear_search)
* [https://en.wikipedia.org/wiki/Binary\_search\_algorithm](https://href.li/?https://en.wikipedia.org/wiki/Binary_search_algorithm)
* [https://en.wikipedia.org/wiki/Breadth-first\_search](https://href.li/?https://en.wikipedia.org/wiki/Breadth-first_search)
* [https://en.wikipedia.org/wiki/Depth-first\_search](https://href.li/?https://en.wikipedia.org/wiki/Depth-first_search)
* [https://en.wikipedia.org/wiki/Exponential\_search](https://href.li/?https://en.wikipedia.org/wiki/Exponential_search)
* [https://en.wikipedia.org/wiki/Fibonacci\_search\_technique](https://href.li/?https://en.wikipedia.org/wiki/Fibonacci_search_technique)
* [https://en.wikipedia.org/wiki/Interpolation\_search](https://href.li/?https://en.wikipedia.org/wiki/Interpolation_search)
* [https://www.geeksforgeeks.org/jump-search/](https://href.li/?https://www.geeksforgeeks.org/jump-search/)
* [https://www.geeksforgeeks.org/linear-search/](https://href.li/?https://www.geeksforgeeks.org/linear-search/)
* [https://www.geeksforgeeks.org/sublist-search-search-a-linked-list-in-another-list/](https://href.li/?https://www.geeksforgeeks.org/sublist-search-search-a-linked-list-in-another-list/)


---

# 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://nielslange.gitbook.io/developer-toolbox/algorithms/space-and-time-complexity.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.
