SlideShare une entreprise Scribd logo
1  sur  10
Télécharger pour lire hors ligne
Chapter 5-1
Data Structures
Assoc. Prof. Dr. Oğuz FINDIK
2016-2017
KBUZEM
KARABUK UNIVERSITY
1
İf we look at the arithmetic expressions, we encounter operand, operator
and parenthesis.
2+3 , (p*q), 2+5*6
For evaluting this expressions, we should parse and them calculate.
<operand><operator><operand> (infix)
Operand: Any object that operation is performed.
Operator: In mathematics and sometimes in computer programming, an
operator is a character that represents an action, as for example x is an
arithmetic operator that represents multiplication.
2
Evaluation of Expressions
 For example 2+3*5-1*4
 To evaluate this expressions you should know precedence of
operator.
 Order of operations
1. Parentheses {()}
2. Exponents 2^3^2 (right to left)
3. Multiplication and division (left to right)
4. Addition and subtraction (left to right)
2*6/3+5-2+8/4*2
3
Evaluation of Expressions
 Prefix (Polish Notation)
 <operator><operand><operand>
 İnfix prefix
 4+5 +45
 p/q /pq
 a*b+c +*abc
4
Evaluation of Expressions
 Postfix (Reverse Polish Notation)
 <operand><operand><operator>
 İnfix prefix postfix
 4+5 +45 45+
 p/q /pq pq/
 a*b+c +*abc ab*c+
5
Evaluation of Expressions
 a*b+c*d-2
 First step we should add parentheses
 {(a*b)+(c*d)}-2
 Next step is that operator will place to end of expression
 {(ab*)+(cd*)}-2
 {ab*cd*+}-2
 ab*cd*+2-
6
Evaluation of prefix and postfix
 2*3+4*5-6=>23*45*+6- (postfix)
 evaluatePostfix(exp){
create a Stack S
for i<-0 to length(exp)-1
{
if (exp[i] is operand)
push(exp[i])
else if (exp[i] is operator){
op2<-pop()
op1<-pop()
temp<perform(op1,op2,exp[i])
push(temp)
}
} return S[top]
}
7
Evaluation of Postfix with Stack
 2*3+4*5-6=>-+*23*456 (prefix)
 This algorithm is same with postfix algorithm. But this
algorithm starts from end of expression.
8
Evaluation of Prefix with Stack
 A+B*C-D*E
 InfixToPostfix(exp){
create a Stack S
String temp<-empty String
for i<-0 to length(exp)-1{
if exp[i] is operand
temp <-temp+exp[i]
else if exp[i] is operator
while(!S.empty()&&HasHigherPrecedence(s.top(),exp[i])){
temp <-temp + s.pop();
}
s.push(exp[i])
}
while(!s.empty()) temp<-temp+s.pop();
Return 1;
}
9
Infix to postfix
 ((A+B)*C-D)*E
 A+(B*C)
10
Infix With parentheses to Postfix

Contenu connexe

Tendances

Java presentation on insertion sort
Java presentation on insertion sortJava presentation on insertion sort
Java presentation on insertion sort_fahad_shaikh
 
2.1.1 functions and their graphs
2.1.1 functions and their graphs2.1.1 functions and their graphs
2.1.1 functions and their graphsNorthside ISD
 
Coin Changing, Binary Search , Linear Search - Algorithm
Coin Changing, Binary Search , Linear Search - AlgorithmCoin Changing, Binary Search , Linear Search - Algorithm
Coin Changing, Binary Search , Linear Search - AlgorithmMd Sadequl Islam
 
Relations and functions (Mariam)
Relations and functions (Mariam)Relations and functions (Mariam)
Relations and functions (Mariam)Mariam Bosraty
 
Chapter 14 Searching and Sorting
Chapter 14 Searching and SortingChapter 14 Searching and Sorting
Chapter 14 Searching and SortingMuhammadBakri13
 
Relational algebra calculus
Relational algebra  calculusRelational algebra  calculus
Relational algebra calculusVaibhav Kathuria
 
7 searching injava-binary
7 searching injava-binary7 searching injava-binary
7 searching injava-binaryirdginfo
 
A Variant of Modified Diminishing Increment Sorting: Circlesort and its Perfo...
A Variant of Modified Diminishing Increment Sorting: Circlesort and its Perfo...A Variant of Modified Diminishing Increment Sorting: Circlesort and its Perfo...
A Variant of Modified Diminishing Increment Sorting: Circlesort and its Perfo...CSCJournals
 
stacks in algorithems and data structure
stacks in algorithems and data structurestacks in algorithems and data structure
stacks in algorithems and data structurefaran nawaz
 
A simple presentation on Relational Algebra
A simple presentation on Relational AlgebraA simple presentation on Relational Algebra
A simple presentation on Relational AlgebraArman Hossain
 

Tendances (19)

Logarithms
LogarithmsLogarithms
Logarithms
 
Java presentation on insertion sort
Java presentation on insertion sortJava presentation on insertion sort
Java presentation on insertion sort
 
2.1.1 functions and their graphs
2.1.1 functions and their graphs2.1.1 functions and their graphs
2.1.1 functions and their graphs
 
Coin Changing, Binary Search , Linear Search - Algorithm
Coin Changing, Binary Search , Linear Search - AlgorithmCoin Changing, Binary Search , Linear Search - Algorithm
Coin Changing, Binary Search , Linear Search - Algorithm
 
Alg2 lesson 2.1
Alg2 lesson 2.1Alg2 lesson 2.1
Alg2 lesson 2.1
 
Relations and functions (Mariam)
Relations and functions (Mariam)Relations and functions (Mariam)
Relations and functions (Mariam)
 
Chapter 14 Searching and Sorting
Chapter 14 Searching and SortingChapter 14 Searching and Sorting
Chapter 14 Searching and Sorting
 
Sorting algorithm
Sorting algorithmSorting algorithm
Sorting algorithm
 
Alg2 lesson 2.1
Alg2 lesson 2.1Alg2 lesson 2.1
Alg2 lesson 2.1
 
Relational algebra calculus
Relational algebra  calculusRelational algebra  calculus
Relational algebra calculus
 
Data Structures & Algorithm design using C
Data Structures & Algorithm design using C Data Structures & Algorithm design using C
Data Structures & Algorithm design using C
 
Functions
FunctionsFunctions
Functions
 
7 searching injava-binary
7 searching injava-binary7 searching injava-binary
7 searching injava-binary
 
Unit 8 searching and hashing
Unit   8 searching and hashingUnit   8 searching and hashing
Unit 8 searching and hashing
 
A Variant of Modified Diminishing Increment Sorting: Circlesort and its Perfo...
A Variant of Modified Diminishing Increment Sorting: Circlesort and its Perfo...A Variant of Modified Diminishing Increment Sorting: Circlesort and its Perfo...
A Variant of Modified Diminishing Increment Sorting: Circlesort and its Perfo...
 
operators in c++
operators in c++operators in c++
operators in c++
 
stacks in algorithems and data structure
stacks in algorithems and data structurestacks in algorithems and data structure
stacks in algorithems and data structure
 
A simple presentation on Relational Algebra
A simple presentation on Relational AlgebraA simple presentation on Relational Algebra
A simple presentation on Relational Algebra
 
Binary search
Binary searchBinary search
Binary search
 

Similaire à Data structure week y 5 1

11 EXPRESSIONS.pptx
11 EXPRESSIONS.pptx11 EXPRESSIONS.pptx
11 EXPRESSIONS.pptxRodmanCajes
 
Introduction to Programming in LISP
Introduction to Programming in LISPIntroduction to Programming in LISP
Introduction to Programming in LISPKnoldus Inc.
 
Although people may be very accustomed to reading and understanding .docx
Although people may be very accustomed to reading and understanding .docxAlthough people may be very accustomed to reading and understanding .docx
Although people may be very accustomed to reading and understanding .docxmilissaccm
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskellgoncharenko
 
INTRODUCTION TO LISP
INTRODUCTION TO LISPINTRODUCTION TO LISP
INTRODUCTION TO LISPNilt1234
 
Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfixSelf-Employed
 
Module 2 - Lists, Tuples, Files.pptx
Module 2 - Lists, Tuples, Files.pptxModule 2 - Lists, Tuples, Files.pptx
Module 2 - Lists, Tuples, Files.pptxGaneshRaghu4
 
Functional programming
Functional programmingFunctional programming
Functional programmingHideshi Ogoshi
 
The Ring programming language version 1.5.4 book - Part 19 of 185
The Ring programming language version 1.5.4 book - Part 19 of 185The Ring programming language version 1.5.4 book - Part 19 of 185
The Ring programming language version 1.5.4 book - Part 19 of 185Mahmoud Samir Fayed
 
Class_IX_Operators.pptx
Class_IX_Operators.pptxClass_IX_Operators.pptx
Class_IX_Operators.pptxrinkugupta37
 
Introduction to Python Values, Variables Data Types Chapter 2
Introduction to Python  Values, Variables Data Types Chapter 2Introduction to Python  Values, Variables Data Types Chapter 2
Introduction to Python Values, Variables Data Types Chapter 2Raza Ul Mustafa
 
Variables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailVariables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailgourav kottawar
 
lecture4 pgdca.pptx
lecture4 pgdca.pptxlecture4 pgdca.pptx
lecture4 pgdca.pptxclassall
 
Lecture_04.2.pptx
Lecture_04.2.pptxLecture_04.2.pptx
Lecture_04.2.pptxRockyIslam5
 

Similaire à Data structure week y 5 1 (20)

11 EXPRESSIONS.pptx
11 EXPRESSIONS.pptx11 EXPRESSIONS.pptx
11 EXPRESSIONS.pptx
 
Introduction to Programming in LISP
Introduction to Programming in LISPIntroduction to Programming in LISP
Introduction to Programming in LISP
 
Although people may be very accustomed to reading and understanding .docx
Although people may be very accustomed to reading and understanding .docxAlthough people may be very accustomed to reading and understanding .docx
Although people may be very accustomed to reading and understanding .docx
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskell
 
INTRODUCTION TO LISP
INTRODUCTION TO LISPINTRODUCTION TO LISP
INTRODUCTION TO LISP
 
STACK Applications in DS
STACK Applications in DSSTACK Applications in DS
STACK Applications in DS
 
Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfix
 
Module 2 - Lists, Tuples, Files.pptx
Module 2 - Lists, Tuples, Files.pptxModule 2 - Lists, Tuples, Files.pptx
Module 2 - Lists, Tuples, Files.pptx
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
The Ring programming language version 1.5.4 book - Part 19 of 185
The Ring programming language version 1.5.4 book - Part 19 of 185The Ring programming language version 1.5.4 book - Part 19 of 185
The Ring programming language version 1.5.4 book - Part 19 of 185
 
Polish
PolishPolish
Polish
 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
 
Class_IX_Operators.pptx
Class_IX_Operators.pptxClass_IX_Operators.pptx
Class_IX_Operators.pptx
 
Introduction to Python Values, Variables Data Types Chapter 2
Introduction to Python  Values, Variables Data Types Chapter 2Introduction to Python  Values, Variables Data Types Chapter 2
Introduction to Python Values, Variables Data Types Chapter 2
 
Variables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailVariables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detail
 
lecture4 pgdca.pptx
lecture4 pgdca.pptxlecture4 pgdca.pptx
lecture4 pgdca.pptx
 
Lecture_04.2.pptx
Lecture_04.2.pptxLecture_04.2.pptx
Lecture_04.2.pptx
 
lecture1.ppt
lecture1.pptlecture1.ppt
lecture1.ppt
 
C# p2
C# p2C# p2
C# p2
 

Plus de karmuhtam

Devre analizi deney malzeme listesi
Devre analizi deney malzeme listesiDevre analizi deney malzeme listesi
Devre analizi deney malzeme listesikarmuhtam
 
Deney 3 ve 4
Deney 3 ve 4Deney 3 ve 4
Deney 3 ve 4karmuhtam
 
Deney 1 ve 2
Deney 1 ve 2Deney 1 ve 2
Deney 1 ve 2karmuhtam
 
Data structure week y 5
Data structure week y 5Data structure week y 5
Data structure week y 5karmuhtam
 
Data structure week y 4
Data structure week y 4Data structure week y 4
Data structure week y 4karmuhtam
 
Data structure week 3
Data structure week 3Data structure week 3
Data structure week 3karmuhtam
 
Data structure week 2
Data structure week 2Data structure week 2
Data structure week 2karmuhtam
 
Data structure week 1
Data structure week 1Data structure week 1
Data structure week 1karmuhtam
 
13. sınıfları başlık dosyaları
13.  sınıfları başlık dosyaları13.  sınıfları başlık dosyaları
13. sınıfları başlık dosyalarıkarmuhtam
 
12. stl örnekler
12.  stl örnekler12.  stl örnekler
12. stl örneklerkarmuhtam
 
11. stl kütüphanesi
11. stl kütüphanesi11. stl kütüphanesi
11. stl kütüphanesikarmuhtam
 
10. istisna isleme
10. istisna isleme10. istisna isleme
10. istisna islemekarmuhtam
 
9. şablonlar
9. şablonlar9. şablonlar
9. şablonlarkarmuhtam
 
8. çok biçimlilik
8. çok biçimlilik8. çok biçimlilik
8. çok biçimlilikkarmuhtam
 
7. kalıtım
7. kalıtım7. kalıtım
7. kalıtımkarmuhtam
 
6. this işaretçisi ve arkadaşlık
6. this işaretçisi ve arkadaşlık6. this işaretçisi ve arkadaşlık
6. this işaretçisi ve arkadaşlıkkarmuhtam
 
5. kurucu, yok edici ve kopyalama fonksiyonları
5. kurucu, yok edici ve kopyalama fonksiyonları5. kurucu, yok edici ve kopyalama fonksiyonları
5. kurucu, yok edici ve kopyalama fonksiyonlarıkarmuhtam
 

Plus de karmuhtam (20)

Devre analizi deney malzeme listesi
Devre analizi deney malzeme listesiDevre analizi deney malzeme listesi
Devre analizi deney malzeme listesi
 
Deney 6
Deney 6Deney 6
Deney 6
 
Deney 5
Deney 5Deney 5
Deney 5
 
Deney 3 ve 4
Deney 3 ve 4Deney 3 ve 4
Deney 3 ve 4
 
Deney 1 ve 2
Deney 1 ve 2Deney 1 ve 2
Deney 1 ve 2
 
Data structure week y 5
Data structure week y 5Data structure week y 5
Data structure week y 5
 
Data structure week y 4
Data structure week y 4Data structure week y 4
Data structure week y 4
 
Data structure week 3
Data structure week 3Data structure week 3
Data structure week 3
 
Data structure week 2
Data structure week 2Data structure week 2
Data structure week 2
 
Data structure week 1
Data structure week 1Data structure week 1
Data structure week 1
 
13. sınıfları başlık dosyaları
13.  sınıfları başlık dosyaları13.  sınıfları başlık dosyaları
13. sınıfları başlık dosyaları
 
12. stl örnekler
12.  stl örnekler12.  stl örnekler
12. stl örnekler
 
11. stl kütüphanesi
11. stl kütüphanesi11. stl kütüphanesi
11. stl kütüphanesi
 
10. istisna isleme
10. istisna isleme10. istisna isleme
10. istisna isleme
 
9. şablonlar
9. şablonlar9. şablonlar
9. şablonlar
 
8. çok biçimlilik
8. çok biçimlilik8. çok biçimlilik
8. çok biçimlilik
 
7. kalıtım
7. kalıtım7. kalıtım
7. kalıtım
 
6. this işaretçisi ve arkadaşlık
6. this işaretçisi ve arkadaşlık6. this işaretçisi ve arkadaşlık
6. this işaretçisi ve arkadaşlık
 
5. kurucu, yok edici ve kopyalama fonksiyonları
5. kurucu, yok edici ve kopyalama fonksiyonları5. kurucu, yok edici ve kopyalama fonksiyonları
5. kurucu, yok edici ve kopyalama fonksiyonları
 
4. yapılar
4. yapılar4. yapılar
4. yapılar
 

Dernier

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 

Dernier (20)

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.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
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 

Data structure week y 5 1

  • 1. Chapter 5-1 Data Structures Assoc. Prof. Dr. Oğuz FINDIK 2016-2017 KBUZEM KARABUK UNIVERSITY 1
  • 2. İf we look at the arithmetic expressions, we encounter operand, operator and parenthesis. 2+3 , (p*q), 2+5*6 For evaluting this expressions, we should parse and them calculate. <operand><operator><operand> (infix) Operand: Any object that operation is performed. Operator: In mathematics and sometimes in computer programming, an operator is a character that represents an action, as for example x is an arithmetic operator that represents multiplication. 2 Evaluation of Expressions
  • 3.  For example 2+3*5-1*4  To evaluate this expressions you should know precedence of operator.  Order of operations 1. Parentheses {()} 2. Exponents 2^3^2 (right to left) 3. Multiplication and division (left to right) 4. Addition and subtraction (left to right) 2*6/3+5-2+8/4*2 3 Evaluation of Expressions
  • 4.  Prefix (Polish Notation)  <operator><operand><operand>  İnfix prefix  4+5 +45  p/q /pq  a*b+c +*abc 4 Evaluation of Expressions
  • 5.  Postfix (Reverse Polish Notation)  <operand><operand><operator>  İnfix prefix postfix  4+5 +45 45+  p/q /pq pq/  a*b+c +*abc ab*c+ 5 Evaluation of Expressions
  • 6.  a*b+c*d-2  First step we should add parentheses  {(a*b)+(c*d)}-2  Next step is that operator will place to end of expression  {(ab*)+(cd*)}-2  {ab*cd*+}-2  ab*cd*+2- 6 Evaluation of prefix and postfix
  • 7.  2*3+4*5-6=>23*45*+6- (postfix)  evaluatePostfix(exp){ create a Stack S for i<-0 to length(exp)-1 { if (exp[i] is operand) push(exp[i]) else if (exp[i] is operator){ op2<-pop() op1<-pop() temp<perform(op1,op2,exp[i]) push(temp) } } return S[top] } 7 Evaluation of Postfix with Stack
  • 8.  2*3+4*5-6=>-+*23*456 (prefix)  This algorithm is same with postfix algorithm. But this algorithm starts from end of expression. 8 Evaluation of Prefix with Stack
  • 9.  A+B*C-D*E  InfixToPostfix(exp){ create a Stack S String temp<-empty String for i<-0 to length(exp)-1{ if exp[i] is operand temp <-temp+exp[i] else if exp[i] is operator while(!S.empty()&&HasHigherPrecedence(s.top(),exp[i])){ temp <-temp + s.pop(); } s.push(exp[i]) } while(!s.empty()) temp<-temp+s.pop(); Return 1; } 9 Infix to postfix
  • 10.  ((A+B)*C-D)*E  A+(B*C) 10 Infix With parentheses to Postfix