# Stack ![](https://i.imgur.com/wjnmvmf.jpg) Link to code page : (a) Solve by Link List :https://nbviewer.jupyter.org/github/sefx5ever/SCU_DSA/blob/master/Week_2/Min%20Stack%28Solution%20by%20LinkedList%29.ipynb (b) Solve by Array :https://nbviewer.jupyter.org/github/sefx5ever/SCU_DSA/blob/master/Week_2/Min%20Stack%28Solution%20by%20List%29.ipynb ### Function: 1. Push :Push element x onto stack. 2. Pop :Removes the element on top of the stack. 3. Top :Get the top element. 4. Get Min :Retrieve the minimum element in the stack. ### Flow Description: After initialize successfully, try to push an interger to stack repeatedly. To find out the minimum number in the stack, apply getMin() function then. Regarding the rule of stack which is LIFO, you only able to remove the last input(the latest input). Other than that, you can also check the top element so. ### Test: ![](https://i.imgur.com/FCIiI7i.png) ### Extra Description: * #### Complexity | STACK | Time Complexity[Average] | Time Complexity[Worst] | | ------------- | ------------- | ------------- | | Push | O(1) | O(1) | | Pop | O(1) | O(1) | | Top | O(1) | O(1) | | Get Min | O(n) | O(n) | * #### Time Taken In LeetCode [By Linked List] ![](https://i.imgur.com/7rXBTDe.png) [By Array] ![](https://i.imgur.com/3SaHDv9.png) ### References: * https://www.youtube.com/watch?v=niBsGw4h5yI * https://www.youtube.com/watch?v=BrVZZZkkGGI&t=515s * https://www.youtube.com/watch?v=wjI1WNcIntg&t=237s # Queue ![](https://i.imgur.com/eHhdvem.jpg) Link to code page : (a) Solve by Link List :https://nbviewer.jupyter.org/github/sefx5ever/SCU_DSA/blob/master/Week_2/Queue%28Solution%20by%20LinkedList%29.ipynb (b) Solve by Array :https://nbviewer.jupyter.org/github/sefx5ever/SCU_DSA/blob/master/Week_2/Queue%28Solution%20by%20List%29.ipynb ### Function: 1. Push :Push element x to the back of queue. 2. Pop :Removes the element from in front of queue. 3. Peek :Get the front element. 4. Empty :Return whether the queue is empty. ### Flow Description: After initialize successfully, push an interger to the queue repeatedly. Then, you can use the peek function to find out the value of index 0. To removes the element from in front of queue, try to take pop as well. Lastly, you can apply function to figure it out and see whether an array is empty. ### Test: ![](https://i.imgur.com/pfJt8vV.png) ### Extra Description: * #### Complexity | QUEUE | Time Complexity[Average] | Time Complexity[Worst] | | ------------- | ------------- | ------------- | | Push | O(1) | O(1) | | Pop | O(1) | O(1) | | Peek | O(1) | O(1) | * #### Time Taken In LeetCode [Linked List] ![](https://i.imgur.com/G2Rcxkg.png) [Array] ![](https://i.imgur.com/YYZlBgi.png) ### References: * https://www.youtube.com/watch?v=gnYM_G1ILm0 * https://www.youtube.com/watch?v=wjI1WNcIntg&t=238s