0% found this document useful (0 votes)
30 views3 pages

Assignment # 1: Course: Instructor

Uploaded by

mrwhitebeared
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views3 pages

Assignment # 1: Course: Instructor

Uploaded by

mrwhitebeared
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

ASSIGNMENT # 1

Course: Data Structures & Algorithms


Instructor: proff: Syeda Nazia Ashraf

BY

Name: Abdul Qadir Jakhro


Roll no: CSC-23F-004
Section: CS3A
Department: Computer Science

Submission Date: 23rd Oct 2024

1) Consider following arithmetic infix expression convert it to prefix & write algorithm and
symbol table which shows status of stack-
 ((A+B) *(C+D)/(E-F)) +G

s.no Input Stack Prefix Algorithm


1 G G Operand, added to prefix
2 + + G Operator, pushed to stack
3 ) +) G Closing parenthesis, pushed
4 F +) FG Closing parenthesis, pushed
5 - +)- FG Operator, pushed to stack
6 E +)- EFG Operand, added to prefix
7 ( + -EFG Opening parenthesis, pop
until )
8 / +/ -EFG Operator, pushed to stack
9 ) +/) -EFG Closing parenthesis, pushed
10 D +/) D-EFG Operand, added to prefix
11 + +/)+ D-EFG Operator, pushed to stack
12 C +/)+ CD-EFG Operand, added to prefix
13 ( +/ +CD-EFG Opening parenthesis, pop
until )
14 * +*/ +CD-EFG Operator, pushed to stack
15 ) +*/) +CD-EFG Closing parenthesis, pushed
16 B +*/) B+CD-EFG Operand, added to prefix
17 + +*/)+ B+CD-EFG Operator, pushed to stack
18 A +*/)+ AB+CD-EFG Operand, added to prefix
19 ( +*/ Opening parenthesis, pop until
+AB+CD-EFG
)
20 +* /+AB+CD-EFG Remaining operator / popped
21 + */+AB+CD-EFG Remaining operator * popped
22 +*/+AB+CD-EEFG Remaining operator + popped

2) Evaluate converted prefix by assigning values: A=14, B= 12, C=10, D=8, E=6, F=4, G=2.

 Prefix expression: + * / + A B + C D - E F G

i) Evaluate + A B:
• A + B = 14 + 12 = 26 ii)
Evaluate + C D:  C + D
= 10 + 8 = 18 iii)
Evaluate / ( + A B ) ( + C
D ):
• 26 / 18 = 1.4 iv) Evaluate
- E F:  E – F = 6 – 4 = 2
v) Evaluate * ( / + A B + C D ) ( - E F ):
• 1.4 × 2 = 2.8 vi) Evaluate + ( * / + A B + C D - E F ) G:
• 2.8 + 2 = 4.8

3) Make a Queue using Array [5] and apply following functions: enqueue(10), enqueue(50)
enqueue(20), enqueue(70), dequeue(), enqueue(100), enqueue(40), enqueue(140)
dequeue(), dequeue(), dequeue()-

 Initial state:

Queue: front -1, rear -1

i. Enqueue (10): front = 0, rear = 0

10
ii. Enqueue (50): front = 0, rear = 1

10 50
iii. Enqueue (20): front = 0, rear = 2

10 50 20
iv. Enqueue (70): front = 0, rear = 3

10 50 20 70
v. Dequeue (): front = 1, rear = 3

50 20 70
vi. Enqueue (100): front = 1, rear = 4

50 20 70 100
vii. Enqueue (40): front = 1, rear = 0 (circular wrap)
40 50 20 70 100 viii.
Enqueue (140): front = 1, rear = 0 (queue full cannot insert 140)

40 50 20 70 100
ix. Dequeue (): front = 2, rear = 0

40 20 70 100
x. Dequeue (): front = 3, rear = 0

40 70 100
xi. Dequeue (): front = 4, rear = 0

40 100

You might also like