Role of Stacks and Queues in Problem Solving
Stacks
A Stack is a linear data structure which follows the LIFO or Last-In-First-Out principle. It basically means that the last element which will be inserted in the stack will be the very first one to leave the stack. Stack contains only a single pointer i.e. the top pointer which points to the very top most element of the following stack. Whenever an element is added in the stack, it is added from the top of the stack, and that element can also be deleted only from the very top of the stack. We can also say that a stack can be defined as a bucket in which the processes of insertion and deletion can only be done from the one end which is commonly known as top of the stack.
Standard Stack Operations
Some very common operations which are implemented on the stack are:
push(): Whenever we add an element in the stack then the operation is known as push operation. If the stack is already full and we try to add an element then the stack overflow occurs.
pop(): When we delete an element from stack, the operation is known as pop. If the stack is already empty and we try to delete an element, stack underflow occurs.
isEmpty(): The isEmpty() function is used to check or detemine whether the stack is empty or not.
isFull(): The isFull() function is used to check or determine whether the stack is full or not.
peek(): The peek() function is used to return the element at the given position.
count(): The count() function returns the total number of elements available in the stack.
The best property of a stack is that we do not need to maintain a table which will contain a record of each and every section of the allocated memory; the only information we need is a single pointer at the top of the stack. To allocate and deallocate, we just have to increment and decrement that top pointer.
- Infix to Postfix Conversion
- Parenthesis Matching
- Many locations, such as editors and photoshop, need redo/undo options provided by stacks.
- Forward and Backward feature in web browsers.
- From left-side to right-side, scan the infix expression.
- If an operand is found, output it.
- If an operator is found and the precedence of the scanned operator is greater than the precedence of the operator in the stack, push it into the stack.
- Otherwise, pop all the operators from the stack that are larger than or equal to the scanned operator in precedence. After that, push the scanned operator into the stack.
- If a '(' appears, push it into the stack.
- If a ‘)’ is encountered, pop the stack and output it until a ‘(‘ is encountered, and discard both the parenthesis.
- Repeat the steps 2-6 until the whole infix expression is scanned.
- Print the output.
- Stacks should be popped and outputted till they are not empty.
The isEmpty() function will return 1 if the stack is empty, otherwise it will return 0.
If the stack is empty and we try to pop an element, stack underflow occurs. Else, it pops and returns the topmost element from the stack.
If the character encountered is an operand, the isOperand() function will return 1, else it will return 0.
- enqueue(): It is used to add or insert an item to the queue.
- dequeue(): It is used to remove or delete an item from the queue.
- peek(): It returns the element at the front of the queue without removing the element.
- isFull(): It checks if the queue is already full or not.
- isEmpty(): It checks if the queue is already empty or not.
- CPU Scheduling, Disk Scheduling
- Breadth First Search
The simplest scheduling algorithm, which schedules processes according to their arrival times. According to the first-come, first-serve scheduling strategy, the process that asks the CPU first gets allocated the CPU first. The FIFO queue is used to implement it. When a process is added to the ready queue, its PCB is linked to the queue's tail. When the CPU becomes available, it is given to the process at the front of the queue. After that, the currently executing process is removed from the queue. FCFS is a scheduling algorithm that is not preemptive.
The Round Robin scheduling method is one of the most widely used scheduling algorithms, and it can be found in almost all operating systems. The Time Sharing is the main emphasis of the algorithm. Every process in this algorithm is carried out in a cyclic manner. In the system, a time quantum is defined as a specific time slice. Each process in the ready queue is given a CPU for that time quantum; if the process's execution is completed within that time, the process will be terminated; otherwise, the process will return to the ready queue and wait for the next turn to complete the execution.
References:
- https://zaid23.medium.com/role-of-stacks-and-queues-in-problem-solving-989d7d68f0d6
- https://pshenavi2.medium.com/role-of-stacks-and-queues-in-problem-solving-a5bbc22305d9
- https://role-of-stackandqueueinproblemsolving.blogspot.com/?m=1
- https://www.geeksforgeeks.org/stack-set-2-infix-to-postfix/
- https://www.geeksforgeeks.org/difference-between-stack-and-queue-data-structures/










Awesome content ππ»
ReplyDeleteInformative
ReplyDeleteGood work
ReplyDeleteNice Content π
ReplyDeleteNice π
ReplyDeleteGood workπ
ReplyDeleteNice work very well done
ReplyDeletePerfectly explained π
ReplyDeletereally helpful πππ»
ReplyDeleteGood work π
ReplyDeleteNice work
ReplyDeleteGood work...
ReplyDeletenice work,informative,nice content etc.
ReplyDeletePerfectly explained
ReplyDeleteNice work
ReplyDeleteall doubts cleared
ReplyDeleteNice work
ReplyDeleteNyc work
ReplyDeleteππ
ReplyDeleteNice work, good content.
ReplyDeleteNice Work ππ
ReplyDeleteNice work
ReplyDeleteExcellent keep up the good work π
ReplyDeleteNice work keep it up π
ReplyDeletewow nice work
ReplyDeletevery informative
ReplyDeleteNice work, informative content
ReplyDeleteKeep it up π
nice work very well explained
ReplyDeleteNice info!
ReplyDeleteNice work..
ReplyDeleteInformative πππ
ReplyDeleteNice content πππ
ReplyDeleteAmazingly explained!
ReplyDeleteNice content π
ReplyDeleteVery useful ππ
ReplyDeleteAmazing content....nicely done
ReplyDeleteNice work
ReplyDeleteInformative
ReplyDeleteNicely done....very good
ReplyDeleteNice content π
ReplyDeleteInformative
ReplyDeleteNice work
ReplyDeleteProperly explained
ReplyDeleteNice work
ReplyDeleteAwsm work
ReplyDeleteImpressive
ReplyDeleteWell explained
ReplyDeleteNice π
ReplyDeleteHelped me a lot.
ReplyDeleteSeems to be great work You did also the content is really the way to go !.
ReplyDeleteInformative content
ReplyDeleteInformation is well served
ReplyDeleteInformative
ReplyDeleteGreat content
ReplyDeleteAwesome work π
ReplyDeleteInteresting content
ReplyDeleteInformative contentπ
ReplyDeleteGreat π
ReplyDeleteWell explained...
ReplyDeleteThanks
Awesome
ReplyDeleteNice work, very informative and easily explained
ReplyDeleteInstructive content
ReplyDeleteInformative and lucidπ
ReplyDeleteInformative content
ReplyDeleteNice work✨
ReplyDeleteNice work, Informative Content
ReplyDeleteHelpful π
ReplyDeleteWell explained ,Informative
ReplyDelete