Skip to content

Commit c662be4

Browse files
authored
Update data_structures.md
1 parent 8594cb3 commit c662be4

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

notes/data_structures.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,56 @@ In computer science, a _collection_ (often interchangeably referred to as a _con
77

88
Every developer should really get to know collections well. It helps you pick the right type of collection for the job, making your code faster, more efficient, and easier to manage in the long run.
99

10-
![G70oT](https://user-images.githubusercontent.com/37275728/185710905-8acd7541-e8ed-4439-a644-5d739b39e783.png)
10+
```mermaid
11+
flowchart TD
12+
Start((Start))
13+
Start --> OrderImportant{Order is Important?}
14+
15+
%% Order‐important branch
16+
OrderImportant -- yes --> LIFO{Last In, First Out?}
17+
LIFO -- yes --> stack[stack]
18+
LIFO -- no --> FIFO{First In, First Out?}
19+
FIFO -- yes --> queue[queue]
20+
FIFO -- no --> BestIn{Best In, First Out?}
21+
BestIn -- yes --> priority_queue[priority_queue]
22+
BestIn -- no --> KeepSorted{Keep Sorted Elements?}
23+
24+
KeepSorted -- yes --> MainPurpose{Main Purpose}
25+
KeepSorted -- no --> InsertMiddle{Insert/erase at middle?}
26+
27+
InsertMiddle -- yes --> Frequent{Frequent Traversals?}
28+
InsertMiddle -- no --> InsertFront{Insert/erase at front?}
29+
30+
Frequent -- yes --> list[list]
31+
Frequent -- no --> InsertFront
32+
33+
InsertFront -- yes --> deque[deque]
34+
InsertFront -- no --> Persistent{Persistent Positions?}
35+
36+
Persistent -- yes --> deque
37+
Persistent -- no --> SizeVaries{Size varies widely?}
38+
39+
SizeVaries -- yes --> deque
40+
SizeVaries -- no --> vector[vector]
41+
42+
MainPurpose -- "In-order Traversals" --> sorted_vector["vector (sorted)"]
43+
MainPurpose -- "Look-up Keys" --> Lookup{Look-up Keys?}
44+
45+
%% Order-not-important & lookup branch
46+
OrderImportant -- no --> Lookup
47+
Lookup -- no --> InsertFront
48+
Lookup -- yes --> AllowDup{Allow Duplicates?}
49+
50+
AllowDup -- no --> Sep1{Separate Key/Value?}
51+
AllowDup -- yes --> Sep2{Separate Key/Value?}
52+
53+
Sep1 -- yes --> unordered_map[unordered_map]
54+
Sep1 -- no --> unordered_set[unordered_set]
55+
56+
Sep2 -- yes --> unordered_multimap[unordered_multimap]
57+
Sep2 -- no --> unordered_multiset[unordered_multiset]
58+
59+
```
1160

1261
### Linked Lists
1362

0 commit comments

Comments
 (0)