FDS Q
FDS Q
To convert an infix expression to a postfix expression using a stack, follow these rules:
4. Operators are pushed onto the stack based on precedence and associativity.
Example Conversion
1. Convert C + D * E:
o D * E → DE*
o C + DE* → CDE*+
2. Convert F * G / H:
o F * G → FG*
o FG* / H → FG*H/
3. Convert exponentiation:
4. Convert A * B - (...):
o A * B → AB*
1. Direct Recursion:
A function calls itself directly.
Example:
2. Indirect Recursion:
Two or more functions call each other in a cyclic manner.
3. Tail Recursion:
The recursive call is the last operation in the function.
Example:
Steps:
1. 23+→5
2. 5 5 * → 25
Final Result: 25
Explain priority queue and state its Application :
A Priority Queue is a special type of queue where each element has a priority, and elements are served based
on their priority rather than the order of arrival (FIFO).
o Unlike a normal queue (FIFO), elements with a higher priority are dequeued before lower-
priority elements.
o If two elements have the same priority, they are dequeued based on the order in which they
were inserted.
o The OS schedules processes based on priority (e.g., real-time tasks get higher priority).
o Documents with a higher priority (e.g., urgent reports) get printed before others.
o Data packets with higher importance (like video streaming) are sent before less important
packets.
Definition:
A Min-Priority Queue is a type of priority queue where the element with the smallest value (highest priority)
is always removed first.
How it Works:
Imagine an operating system (OS) scheduler where processes have a priority based on their
execution time (shorter jobs get executed first).
In a Circular Queue, the rear pointer wraps around when it reaches the end, allowing efficient reuse of empty
spaces.
Insertions and deletions are always O(1) due to rear and front pointers
Backtracking is a systematic and recursive algorithmic technique used to solve problems incrementally by
trying possible solutions and discarding those that fail to meet the required conditions.