Stable/Patient Sort: Bit-Manipulation-To-Solve-Problems-Easily-And-Efficiently
Stable/Patient Sort: Bit-Manipulation-To-Solve-Problems-Easily-And-Efficiently
Sorting Algorithms
Stable/Patient Sort
Create new piles when there is larger number than the other piles. This results in
increasing sequences and is good for largest increasing sequence.
Bit Manipulation
https://leetcode.com/problems/sum-of-two-integers/discuss/84278/A-summary%3A-how-to-use-
bit-manipulation-to-solve-problems-easily-and-efficiently
"""
check parity (odd or even): & 1
get last bit: x & (x-1)
two complement : res = -(1<<32 - res)
- get the value of a negative bit representation
- we convert it to a value 1<<32, then we need to subtract to get the complement
"""
Negative bit value: the complement of the bit except the last 1 stays 1 bit
5: 0000000000000101
-5: 1111111111111011
8: 0000000000001000
-8: 1111111111111000
12: 0000000000001100
-12: 1111111111110100
Subsequence vs Substring
Subarray: contiguous sequence in an array
Subsequence: Need not to be contiguous, but maintains order
Subset: keeps relative order but does not need to be contiguous