graph LR;
Z(( ))
Z -->|Key-Value Pairs?| B(Duplicates?)
B -->|yes| C(Ordered?)
C -->|yes| D[multimap]
C -->|no| E[unordered_multimap]
B -->|no| F(Ordered?)
F -->|yes| G[map]
F -->|no| H[unordered_map]
Z -->|Values?| J(Duplicates?)
J -->|yes| K(Ordered?)
K -->|sorted| L[multiset]
K -->|insertion order| M[vector, array, deque, list, forward_list]
K -->|no| N[unordered_multiset]
J -->|no| O(Ordered?)
O -->|yes| P[set]
O -->|no| Q[unordered_set]
rebuilding tree from a trasversal: 1 3 2 5 6 8 7 4
recursively:
-> 4 root, 1 3 2 left, 5 6 8 7 right
-> left: 2 root, 1 left, 3 right
-> right: 7 root, 5 6 left, 8 right
-> for pre- and post-order, the tree is unique, but not for inorder
Heap
extract min/max:
delete root (largest/smallest element)
make last element new root
sift down from root
-> extraction in
quiz: number of MaxHeaps of keys
-> root node and structure is fixed, but the rest of the heap is just all possible combinations
e.g.
3: 2 possibilities
6: possibilities
-> root fixed: 5 elements left, 3 elements in left subtree, 2 in right
-> we know: N(3) options for left subtree, only a single option for right subtree
There is a line with two points and a second line with . If the cross product between is positive and is negative, the two vertices of are on different sides of is either intersecting with or behind .
By the cross product also from () and they are also not on the same side of (have different signs), we can be sure that and are intersecting.
int sgn(int num) {
if (num > 0) return 1;
if (num < 0) return -1;
return 0; // (?) is this correct
}
bool is_intersecting(line a, line b) {
// check if a and b possibly intersects
line ab1 = line(a.p1, b.p1);
line ab2 = line(a.p1, b.p2);
if(sgn(cross_product(a, ab1)) != sgn(cross_product(a, ab2))) {
// check if a and b intersect, from b
line ba1 = line(b.p1, a.p1);
line ba2 = line(b.p1, a.p2);
if(sgn(cross_product(b, ba1)) != sgn(cross_product(b, ba2)))
return true;
}
return false;
}