Data Structures and Algorithms · Unit 2 · 4 hrs
Stack
Exam-focused notes for Stack (Data Structures and Algorithms, CSC211): what the TU syllabus asks and how it has actually been tested, with 11 solved past questions from this unit.
What this unit covers
- Basic Concept of Stack, Stack as an ADT, Stack Operations, Stack Applications
- Conversion from infix to postfix/prefix expression, Evaluation of postfix/ prefix expressions
Conversion from infix to postfix/prefix expression, Evaluation of postfix/ prefix expressions
Convert the infix expression A+(((B-C)*(D-E)+F)/G$(H-I) into post expression using stack. [5]
Infix expression: A+(((B-C)(D-E)+F)/G$(H-I)) Note: The original problem text shows an apparent typo with unbalanced parentheses. Counting the brackets: - Open parens: ( before ((, giving 4 opening: ( ( ( ( - Actually reading A+(((B-C)(D-E)+F)/G$(H-I)) the b...
Full solved answer →How recursive algorithm uses stack to store intermediate results? Illustrate with an example. Convert the infix expression A+B*(C/D+F)-G/H into postfix expression using stack.[10]
- Task 1: Explain how a recursive algorithm uses a stack for intermediate results, with an example. - Task 2 (numeric/symbolic): Infix expression to convert to postfix: $$A + B \times (C / D + F) - G / H$$ - Method required: Stack-based conversion. - Marks:...
Full solved answer →Evaluate the postfix expression 574-*8/4+ using stack. [5]
- Postfix expression: 5 7 4 - 8 / 4 + - Data structure to use: Stack 1. Scan the expression left to right. 2. If the symbol is an operand, push it onto the stack. 3. If the symbol is an operator, pop the top two operands: - op2 = first pop (right operand) -...
Full solved answer →Evaluate the expression ABCD-x+ using stack where A=5, B=4, C=3 and D=7. [5]
- Postfix expression: A B C D - x + where x denotes multiplication - Operand values: - $A = 5$ - $B = 4$ - $C = 3$ - $D = 7$ So the expression to evaluate is: A B C D - + --- - Scan left to right. - Operand → push onto stack. - Operator → pop top two operan...
Full solved answer →Explain algorithm for evaluation of postfix expression using stack. [5]
In a postfix expression (also called Reverse Polish Notation), operators follow their operands. A stack is used to hold operands until an operator is encountered, at which point the operation is performed. --- 1. Scan the postfix expression from left to rig...
Full solved answer →How can you use stack to convert an infix expression to postfix? Convert infix expression (A+B)*(C-D) to postfix using stack.[10]
A stack is used to temporarily hold operators and parentheses so that operators are emitted to the output in the correct order of precedence. We scan the infix expression left to right and apply the following rules: 1. Operand → append directly to the postf...
Full solved answer →Explain the infix to post fix conversion algorithm. [5]
Infix notation is the standard mathematical notation where operators are placed between operands (e.g., A + B). Postfix notation (Reverse Polish Notation) places operators after their operands (e.g., A B +). The conversion uses a stack data structure to tem...
Full solved answer →Basic Concept of Stack, Stack as an ADT, Stack Operations, Stack Applications
Explain push and pop operations of stack. What are different applications of stack? [5]
A stack is a linear data structure in which insertion and deletion of elements takes place at only one end, called the top. It follows the LIFO (Last In First Out) principle, meaning the last element inserted is the first one to be removed. --- The PUSH ope...
Full solved answer →What is stack? What are the different applications of stack? Explain stack operations with example.[10]
A stack is a linear data structure in which an element may be inserted or deleted only at one end (called the top of the stack). Elements are removed from a stack in the reverse order of that in which they were inserted. Stack follows the principle of LIFO ...
Full solved answer →Compare stack with queue. How is linear queue different from circular queue? [5]
--- Basis Stack Queue --------- Principle Last In First Out (LIFO) First In First Out (FIFO) End of Operation Insertion and deletion both occur at one end called the top Insertion occurs at the rear end and deletion occurs at the front end Operations PUSH (...
Full solved answer →What is ADT? Discuss stack as an ADT. [5]
--- Definition: An Abstract Data Type (ADT) is a type or a class for objects whose behaviour is defined by a set of values and a set of operations. It does not specify how data will be organized in memory and what algorithms will be used for implementing th...
Full solved answer →Make Unit 2 stick
Practice CSC211 with flashcards & quizzes