Skip to content

Commit 5d948d7

Browse files
Артём МошнинАртём Мошнин
authored andcommitted
s
1 parent 16021d9 commit 5d948d7

File tree

1 file changed

+78
-1
lines changed

1 file changed

+78
-1
lines changed

README.md

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,83 @@
11
# Data Structures and Algorithms
22

3-
### Time and Space Complexity Analysis
3+
## Data Structures
4+
5+
A data structure is a particular way of organizing and storing data in a computer so that it can
6+
be accessed and modified efficiently. More precisely, a data structure is a collection of data
7+
values, the relationships among them, and the functions or operations that can be applied to
8+
the data.
9+
10+
`B` - Beginner, `A` - Advanced
11+
12+
- `B` [Linked List](src/data-structures/linked-list)
13+
14+
## Algorithms
15+
16+
An algorithm is an unambiguous specification of how to solve a class of problems. It is
17+
a set of rules that precisely define a sequence of operations.
18+
19+
`B` - Beginner, `A` - Advanced
20+
21+
### Algorithms by Topic
22+
23+
- **Strings**
24+
- `A` [Levenshtein Distance](src/algorithms/string/levenshtein-distance) - minimum edit distance between two sequences
25+
26+
## Useful Information
27+
28+
### References
29+
30+
[▶ Data Structures and Algorithms on YouTube](https://www.youtube.com/playlist?list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8)
31+
32+
### Big O Notation
33+
34+
_Big O notation_ is used to classify algorithms according to how their running time or space requirements grow as the input size grows.
35+
On the chart below you may find most common orders of growth of algorithms specified in Big O notation.
36+
37+
![Big O graphs](./assets/big-o-graph.png)
38+
39+
Source: [Big O Cheat Sheet](http://bigocheatsheet.com/).
40+
41+
Below is the list of some of the most used Big O notations and their performance comparisons against different sizes of the input data.
42+
43+
| Big O Notation | Computations for 10 elements | Computations for 100 elements | Computations for 1000 elements |
44+
| -------------- | ---------------------------- | ----------------------------- | ------------------------------ |
45+
| **O(1)** | 1 | 1 | 1 |
46+
| **O(log N)** | 3 | 6 | 9 |
47+
| **O(N)** | 10 | 100 | 1000 |
48+
| **O(N log N)** | 30 | 600 | 9000 |
49+
| **O(N^2)** | 100 | 10000 | 1000000 |
50+
| **O(2^N)** | 1024 | 1.26e+29 | 1.07e+301 |
51+
| **O(N!)** | 3628800 | 9.3e+157 | 4.02e+2567 |
52+
53+
### Data Structure Operations Complexity
54+
55+
| Data Structure | Access | Search | Insertion | Deletion | Comments |
56+
| ---------------------- | :----: | :----: | :-------: | :------: | :--------------------------------------------------- |
57+
| **Array** | 1 | n | n | n | |
58+
| **Stack** | n | n | 1 | 1 | |
59+
| **Queue** | n | n | 1 | 1 | |
60+
| **Linked List** | n | n | 1 | n | |
61+
| **Hash Table** | - | n | n | n | In case of perfect hash function costs would be O(1) |
62+
| **Binary Search Tree** | n | n | n | n | In case of balanced tree costs would be O(log(n)) |
63+
| **B-Tree** | log(n) | log(n) | log(n) | log(n) | |
64+
| **Red-Black Tree** | log(n) | log(n) | log(n) | log(n) | |
65+
| **AVL Tree** | log(n) | log(n) | log(n) | log(n) | |
66+
| **Bloom Filter** | - | 1 | 1 | - | False positives are possible while searching |
67+
68+
### Array Sorting Algorithms Complexity
69+
70+
| Name | Best | Average | Worst | Memory | Stable | Comments |
71+
| ------------------ | :-----------: | :---------------------: | :-------------------------: | :----: | :----: | :------------------------------------------------------------ |
72+
| **Bubble sort** | n | n<sup>2</sup> | n<sup>2</sup> | 1 | Yes | |
73+
| **Insertion sort** | n | n<sup>2</sup> | n<sup>2</sup> | 1 | Yes | |
74+
| **Selection sort** | n<sup>2</sup> | n<sup>2</sup> | n<sup>2</sup> | 1 | No | |
75+
| **Heap sort** | n&nbsp;log(n) | n&nbsp;log(n) | n&nbsp;log(n) | 1 | No | |
76+
| **Merge sort** | n&nbsp;log(n) | n&nbsp;log(n) | n&nbsp;log(n) | n | Yes | |
77+
| **Quick sort** | n&nbsp;log(n) | n&nbsp;log(n) | n<sup>2</sup> | log(n) | No | Quicksort is usually done in-place with O(log(n)) stack space |
78+
| **Shell sort** | n&nbsp;log(n) | depends on gap sequence | n&nbsp;(log(n))<sup>2</sup> | 1 | No | |
79+
| **Counting sort** | n + r | n + r | n + r | n + r | Yes | r - biggest number in array |
80+
| **Radix sort** | n \* k | n \* k | n \* k | n + k | Yes | k - length of longest key |
481

582
<details>
683
<summary>Time/Space complexity for for Data Structure Operations</summary>

0 commit comments

Comments
 (0)