Points to Remember - DSA

2025-04-14 23:56

#### Tags: dsa
  1. In headq.heappush(q, <tuple>), the fist index of tuple is given highest priority. For example:

    from heapq import heappush
    q = []
    heappush(q, (4, 5))
    print(q) # O/P - [(4, 5)]
    heappush(q, (5, 3))
    print(q) # O/P - [(4, 5), (5, 3)]
    heappush(q, (4, 2))
    print(q) # O/P - [(4, 2), (5, 3), (4, 5)]
    heappush(q, (2, 1))
    print(q) # O/P - [(2, 1), (4, 2), (4, 5), (5, 3)]
    
  2. Monotonic Stack means, stack that is either strictly increasing or decreasing.
    (Topic - Monotonic Stack#Common model of monotonic stack)

Reference