DSA Basic Notes:

DSA #

1. Bitwise Operations for addition/subtraction/division/multiplcation: #

Addition without using + operator:

  • a + b = ?
  • xor_val = a ^ b
  • and_val = a & b « 1
  • while and_val != 0:
    • xor_val = xor_val ^ and_val
    • and_val = xor_val & and_val « 1
  • return xor_val

https://leetcode.com/problems/sum-of-two-integers/description/

Multiplication (can be applied to division using right shift instead of left shift):

https://stackoverflow.com/questions/2776211/how-can-i-multiply-and-divide-using-only-bit-shifting-and-adding/2777225#2777225

2. Heap: #

Heap is nothing but a priority queue:

3. Array: #