0% found this document useful (0 votes)
18 views

COMSATS University, Islamabad: Islamabad Campus Department of Computer Science

1. The document contains questions about stacks, priority queues, and deques. 2. For question 1, the student is asked to convert infix expressions to postfix and evaluate the postfix expressions. 3. For question 2, the student must write algorithms for insertion, deletion, and display for priority queue implementations using an array of structures, 2D array, and linked list. 4. For question 3, the student must write algorithms for PUSH, POP, INJECT, and EJECT operations on a deque data structure.

Uploaded by

Salman Khalid
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

COMSATS University, Islamabad: Islamabad Campus Department of Computer Science

1. The document contains questions about stacks, priority queues, and deques. 2. For question 1, the student is asked to convert infix expressions to postfix and evaluate the postfix expressions. 3. For question 2, the student must write algorithms for insertion, deletion, and display for priority queue implementations using an array of structures, 2D array, and linked list. 4. For question 3, the student must write algorithms for PUSH, POP, INJECT, and EJECT operations on a deque data structure.

Uploaded by

Salman Khalid
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

COMSATS University, Islamabad

Islamabad Campus
Department of Computer Science

NAME: SALMAN KHALID


ROLL NO. SP18-BSE-169

Question # 1 (Applications of Stack)


a) Convert the following infix expression into its equivalent postfix expression. Write each step of this conversion.
1. (A + B)*(C – D )
2. A ^ B * C – D + E/F
3. A/(B+C*D-E)
4. A-B*C+D/E
5. (A+B)^2 -(C-D)/2
Evaluate the postfix expression (part a) when:
A = 12 , B = 3 ,C = 7 , D = 4 ,E = 2 and F = 5
Question # 2
A priority Queue can be implement using following methods:
1. Using Array of Structure
Where array elements of priority queue can have the following structure:
struct data
{
int item;
int priority;
int order;
};
2. Using 2D Array
3. Linked List
Write algorithms for insertion, deletion and display for above implementation methods
Question # 3
A DEQUE is a data structure consisting of a list of items, on which the following operations are possible:
PUSH ( X,D) : Insert item X on the front end of DEQUE D.
POP(D) : Remove the front item from DEQUE D and return it.
Inject(X, D) : Insert item X on the rear end of DEQUE D.
Eject(D) : Remove the rear item from DEQUE D and return it.
Write algorithms for above operations.

Spring 2019 Page 1


Q#1
ALGORITHM:

Let, X is an arithmetic expression written in infix notation. This algorithm finds the
equivalent postfix expression Y.

1. Push “(“onto Stack, and add “)” to the end of X.


2. Scan X from left to right and repeat Step 3 to 6 for each element of X until the
Stack is empty.
3. If an operand is encountered, add it to Y.
4. If a left parenthesis is encountered, push it onto Stack.
5. If an operator is encountered ,then:
1. Repeatedly pop from Stack and add to Y each operator (on the top of Stack)
which has the same precedence as or higher precedence than operator.
2. Add operator to Stack.
[End of If]
6. If a right parenthesis is encountered ,then:
1. Repeatedly pop from Stack and add to Y each operator (on the top of Stack)
until a left parenthesis is encountered.
2. Remove the left Parenthesis.
[End of If]
[End of If]
7. END.

a):

1. (A + B)*(C – D )
Postfix expression: A B + C – D * or 12 3 + 7-4*

2. A ^ B * C – D + E/F
Postfix expression: A B ^ C – D * E F/ + or 12 3^7-4*25/

3. A/(B+C*D-E)
Postfix expression: A B C D * + E - / or 12 3 7 4 * + 2 - /

4. A-B*C+D/E
Postfix expression: A B C * - D E / + or 12 3 7 * - 4 2 / +

5. (A+B)^2 -(C-D)/2
Postfix expression: A B + 2 ^ C D - 2 / - or 12 3 + 2 ^ 7 4 - 2 / -

Spring 2019 Page 2


Spring 2019 Page 3

You might also like