Posts

Showing posts from May, 2024

Applications of Stack Data Structure स्टैक डेटा स्ट्रक्चर के अनुप्रयोग

  Stack is used to perform following task:- स्टैक का प्रयोग निम्न कार्यो को पूर्ण करने के लिए किया जाता है:-   1. Stack is used to store intermediate data (context) which is occurred in  recursion  process when recursion function ends all the elements of stack popped in one by one manner and evaluated then we provide result to the user. Hence stack must required in every recursive program. स्टैक का प्रयोग रिकर्शन प्रक्रिया में पारायुक्त किये जाने वाले इंटरमीडिएट डाटा (कॉन्टेक्स्ट) को रखने के लिए किया जाता है। जब रिकर्शन कॉल समाप्त होती है, तब एक के बाद एक क्रम से सभी एलिमेंट को पॉप कर लिया जाता है एवं उनकी गणना की जाती है जिससे परिणामी हल प्राप्त होता है। अत: रिकर्सिव फंक्शन के लिए स्टैक डाटा स्ट्रक्चर अनिवार्य है।     2. Stack is used in evaluation process of each arithmetic and logical expression. First of all infix expression of program is converted into postfix expression using stack. After that postfix expression is evaluate by CPU and stack must ...

Algorithm for evaluation of postfix expressions/notations with examples

  Algorithm for e valuation of postfix  expressions/notations:- (1) Add right parenthesis ')' at the end of postfix expression P. (2) Scan P from left to right and repeat steps (3) and (4) until right parenthesis occurred.  (3) If an operand encountered then push it into the stack. (4) If an operator encountered then operate top two elements of stack as follows:- (a) Evaluate BoA where A is top element and B is next top element.  (b) Push the result into the stack. (5)If right parenthesis ')' encountered then pop the final result from the stack, it means evaluation is completed. (6) Exit. Examples:- 1.) P = 52/ 42^3*+ solve :- given expression  P = 52/42^3*+ s.no. Scanned symbol Stack 1 5 5 2 2 5,2 3 / 2 4 4 2, 4 5 2 2, 4, 2 6 ^ 2, 16 7 3 2, 16, 3 8 *   2, 48 9 + 50 answer is 50. 2.) P = AB*C/DE*F/- where A=5, B=2, C=7, D=4, E=1 AND F=3 Solve :- given expression  P = 52*7/41*3/- s.no. Scanned symbol Stack 1 5 5 2 2 5, 2 3 * 10 4 7   10, 7 5 / 1 6 ...

Algorithm for infix to postfix expression conversion using stack with example.

  Algorithm for i nfix to postfix expression conversion- 1. Push left parenthesis '(' into the stack and add right parenthesis ')' at the end of infix expression. 2. Scan expressions from left to right and repeat steps from (3) to (6) for each element of expression until the stack will be empty. 3. If a  operand occurred then add it to the post fix expression. 4. If left parenthesis '(' encountered then push it into the stack. 5. If an operator then performed following steps :- (a) repeatedly pop each operator from stack which has higher or equal precedence then input operator. (b) push result and then input operator into the stack. 6. If right parenthesis ')' occurred then perform following steps:- a. Repeatedly pop each operator from stack until left parenthesis '('  will occurred. b. Remove left parenthesis '(' from stack and do not add it into P. 7. Exit. Change following infix expression into prefix and postfix expression. 1.) 5/2 + ...