SlideShare a Scribd company logo
1 of 4
DATA STRUCTURE ASSIGNMENT #2

Comsats institute Of Information Technology Islamabad

Subject :

Data Structure

Assignment#:

2

Submitted to:

Sir Zaheer Ul Hassan Sani

Submitted by:

Haq Nawaz

Reg#:

Sp12-bcs-089

Submission date:

2 November 2013

SP12-BCS-089

Page 1
DATA STRUCTURE ASSIGNMENT #2

Task a:
We have infix expression in the form of:

((A-B)+C*(D+E))-(F+G)
Now reading expression from right to left and pushing operators into stack and
variables to output stack

Input
)
G
+
F
(
)
)
E
+
D
(
*
C
+
)
B
A
(
(
EMPTY
SP12-BCS-089

Output_stack
EMPTY
G
G
GF
GF+
GF+
GF+
GF+
GF+E
GF+E
GF+ED
GF+ED+
GF+ED+
GF+ED+C
GF+ED+C*
GF+ED+C*
GF+ED+C*B
GF+ED+C*B
GF+ED+C*BA
GF+ED+C*BAGF+ED+C*BA-+
GF+ED+C*BA-+-

Stack
)
)
)+
)+
EMPTY
-)
-))
-))
-))+
-))+
-)
-)*
-)*
-)+
-)+)
-)+)
-)+)-)+)-)+
EMPTY
Page 2
DATA STRUCTURE ASSIGNMENT #2

Out put_stack = GF+ED+C*BA-+Reversing the output_stack we get prefix expression:

-+-AB*C+DE+FG

Task b:
Evaluating the prefix expression:
Assigning the values to variables

A=7
B=6
C=5
D=4
Reading expression from right to left:
reading
1
2
+
3
4
+
5
*
6
7
+
-

operation
1
12
12+
33
334
3 3 4+
375
3 7 5*
3 35 6
3 35 6 7
3 35 6 73 35 1+
3 36 -

E=3

F=2

G=1

Stack_output
Empty
3
3
3
37
37
3 7 35
3 35
3 35
3 35 1
3 36
33

Pop stack_output : 33

Result=33

SP12-BCS-089

Page 3
DATA STRUCTURE ASSIGNMENT #2

Comparing both expressions evaluations:

((A-B)+C*(D+E))-(F+G)
((7-6)+5(4+3))-(2+1)
(1+5*7)-3
1+35-3
36-3
33

SP12-BCS-089

Page 4

More Related Content

What's hot

Stack - Data Structure - Notes
Stack - Data Structure - NotesStack - Data Structure - Notes
Stack - Data Structure - NotesOmprakash Chauhan
 
Expression evaluation
Expression evaluationExpression evaluation
Expression evaluationJeeSa Sultana
 
Applications of stack
Applications of stackApplications of stack
Applications of stackeShikshak
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - NotesOmprakash Chauhan
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemMadhu Bala
 
Poset in Relations(Discrete Mathematics)
Poset in Relations(Discrete Mathematics)Poset in Relations(Discrete Mathematics)
Poset in Relations(Discrete Mathematics)Rachana Pathak
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexityAnkit Katiyar
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and boundAbhishek Singh
 
Multiple Choice Questions - Numerical Methods
Multiple Choice Questions - Numerical MethodsMultiple Choice Questions - Numerical Methods
Multiple Choice Questions - Numerical MethodsMeenakshisundaram N
 
The principle of inclusion and exclusion for three sets by sharvari
The principle of inclusion and exclusion for three sets by sharvariThe principle of inclusion and exclusion for three sets by sharvari
The principle of inclusion and exclusion for three sets by sharvariDeogiri College Student
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applicationsJsaddam Hussain
 

What's hot (20)

Circular Queue data structure
Circular Queue data structureCircular Queue data structure
Circular Queue data structure
 
Bisection method
Bisection methodBisection method
Bisection method
 
Stack - Data Structure - Notes
Stack - Data Structure - NotesStack - Data Structure - Notes
Stack - Data Structure - Notes
 
stack & queue
stack & queuestack & queue
stack & queue
 
Expression evaluation
Expression evaluationExpression evaluation
Expression evaluation
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
 
Stack
StackStack
Stack
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Huffman codes
Huffman codesHuffman codes
Huffman codes
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 
Poset in Relations(Discrete Mathematics)
Poset in Relations(Discrete Mathematics)Poset in Relations(Discrete Mathematics)
Poset in Relations(Discrete Mathematics)
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and bound
 
Multiple Choice Questions - Numerical Methods
Multiple Choice Questions - Numerical MethodsMultiple Choice Questions - Numerical Methods
Multiple Choice Questions - Numerical Methods
 
The principle of inclusion and exclusion for three sets by sharvari
The principle of inclusion and exclusion for three sets by sharvariThe principle of inclusion and exclusion for three sets by sharvari
The principle of inclusion and exclusion for three sets by sharvari
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
Big O Notation
Big O NotationBig O Notation
Big O Notation
 

Viewers also liked

Infix-Postfix expression conversion
Infix-Postfix expression conversionInfix-Postfix expression conversion
Infix-Postfix expression conversionRashmiranja625
 
My lecture infix-to-postfix
My lecture infix-to-postfixMy lecture infix-to-postfix
My lecture infix-to-postfixSenthil Kumar
 
Infix prefix postfix expression -conversion
Infix  prefix postfix expression -conversionInfix  prefix postfix expression -conversion
Infix prefix postfix expression -conversionSyed Mustafa
 
Infix to-postfix examples
Infix to-postfix examplesInfix to-postfix examples
Infix to-postfix examplesmua99
 

Viewers also liked (6)

Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions
 
Infix to postfix
Infix to postfixInfix to postfix
Infix to postfix
 
Infix-Postfix expression conversion
Infix-Postfix expression conversionInfix-Postfix expression conversion
Infix-Postfix expression conversion
 
My lecture infix-to-postfix
My lecture infix-to-postfixMy lecture infix-to-postfix
My lecture infix-to-postfix
 
Infix prefix postfix expression -conversion
Infix  prefix postfix expression -conversionInfix  prefix postfix expression -conversion
Infix prefix postfix expression -conversion
 
Infix to-postfix examples
Infix to-postfix examplesInfix to-postfix examples
Infix to-postfix examples
 

Recently uploaded

MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 

Recently uploaded (20)

MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 

Conversion from infix to prefix using stack

  • 1. DATA STRUCTURE ASSIGNMENT #2 Comsats institute Of Information Technology Islamabad Subject : Data Structure Assignment#: 2 Submitted to: Sir Zaheer Ul Hassan Sani Submitted by: Haq Nawaz Reg#: Sp12-bcs-089 Submission date: 2 November 2013 SP12-BCS-089 Page 1
  • 2. DATA STRUCTURE ASSIGNMENT #2 Task a: We have infix expression in the form of: ((A-B)+C*(D+E))-(F+G) Now reading expression from right to left and pushing operators into stack and variables to output stack Input ) G + F ( ) ) E + D ( * C + ) B A ( ( EMPTY SP12-BCS-089 Output_stack EMPTY G G GF GF+ GF+ GF+ GF+ GF+E GF+E GF+ED GF+ED+ GF+ED+ GF+ED+C GF+ED+C* GF+ED+C* GF+ED+C*B GF+ED+C*B GF+ED+C*BA GF+ED+C*BAGF+ED+C*BA-+ GF+ED+C*BA-+- Stack ) ) )+ )+ EMPTY -) -)) -)) -))+ -))+ -) -)* -)* -)+ -)+) -)+) -)+)-)+)-)+ EMPTY Page 2
  • 3. DATA STRUCTURE ASSIGNMENT #2 Out put_stack = GF+ED+C*BA-+Reversing the output_stack we get prefix expression: -+-AB*C+DE+FG Task b: Evaluating the prefix expression: Assigning the values to variables A=7 B=6 C=5 D=4 Reading expression from right to left: reading 1 2 + 3 4 + 5 * 6 7 + - operation 1 12 12+ 33 334 3 3 4+ 375 3 7 5* 3 35 6 3 35 6 7 3 35 6 73 35 1+ 3 36 - E=3 F=2 G=1 Stack_output Empty 3 3 3 37 37 3 7 35 3 35 3 35 3 35 1 3 36 33 Pop stack_output : 33 Result=33 SP12-BCS-089 Page 3
  • 4. DATA STRUCTURE ASSIGNMENT #2 Comparing both expressions evaluations: ((A-B)+C*(D+E))-(F+G) ((7-6)+5(4+3))-(2+1) (1+5*7)-3 1+35-3 36-3 33 SP12-BCS-089 Page 4