Why is the constant always dropped from big O analysis?

There’s a distinction between “are these constants meaningful or relevant?” and “does big-O notation care about them?” The answer to that second question is “no,” while the answer to that first question is “absolutely!” Big-O notation doesn’t care about constants because big-O notation only describes the long-term growth rate of functions, rather than their absolute … Read more

Implement a queue in which push_rear(), pop_front() and get_min() are all constant time operations

You can implement a stack with O(1) pop(), push() and get_min(): just store the current minimum together with each element. So, for example, the stack [4,2,5,1] (1 on top) becomes [(4,4), (2,2), (5,2), (1,1)]. Then you can use two stacks to implement the queue. Push to one stack, pop from another one; if the second … Read more