Stacks and Queues

Time Complexity

Insertion : What would be the time for inserting an element into a stack? Since you're inserting an element to the top of the stack, time is constant O(1). Deletion : Similar to insertion, deletion takes contant time O(1) too. Search : How much time would it take to search for a particular element inside a stack? Searching for a particular element would mean traversing the entire stack in the worst case, so search operation takes linear time O(n).