SlideShare a Scribd company logo
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

More Related Content

PPSX
Analytic Geometry
PPTX
List manipulation
PPT
L10 sorting-searching
PPTX
Unit 2 application of stack
PPTX
Sorting and searching arrays binary search algorithm
PPTX
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PDF
Binary Search - Design & Analysis of Algorithms
Analytic Geometry
List manipulation
L10 sorting-searching
Unit 2 application of stack
Sorting and searching arrays binary search algorithm
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
Binary Search - Design & Analysis of Algorithms

What's hot (19)

PPT
Logarithms
PPTX
Java presentation on insertion sort
PPTX
2.1.1 functions and their graphs
PPTX
Coin Changing, Binary Search , Linear Search - Algorithm
PPTX
Alg2 lesson 2.1
PPTX
Relations and functions (Mariam)
PDF
Chapter 14 Searching and Sorting
PDF
Sorting algorithm
PPTX
Alg2 lesson 2.1
PPTX
Relational algebra calculus
PDF
Data Structures & Algorithm design using C
PPTX
PPTX
7 searching injava-binary
PPTX
Unit 8 searching and hashing
PDF
A Variant of Modified Diminishing Increment Sorting: Circlesort and its Perfo...
ODP
operators in c++
PPT
stacks in algorithems and data structure
PPTX
A simple presentation on Relational Algebra
PPTX
Binary search
Logarithms
Java presentation on insertion sort
2.1.1 functions and their graphs
Coin Changing, Binary Search , Linear Search - Algorithm
Alg2 lesson 2.1
Relations and functions (Mariam)
Chapter 14 Searching and Sorting
Sorting algorithm
Alg2 lesson 2.1
Relational algebra calculus
Data Structures & Algorithm design using C
7 searching injava-binary
Unit 8 searching and hashing
A Variant of Modified Diminishing Increment Sorting: Circlesort and its Perfo...
operators in c++
stacks in algorithems and data structure
A simple presentation on Relational Algebra
Binary search
Ad

Similar to Data structure week y 5 1 (20)

PPTX
Infix to postfix
PPTX
Lecture_04.2.pptx
PPTX
Precedence of operators IN C PROGRAMMING
PPTX
Basic operators and it's types in c languages
PPT
operator
PPTX
data structure notes for engi DSA1 (2).pptx
PDF
computer notes - Evaluating postfix expressions
PPT
Arithmetic notation conversion infix to1
PPT
Unit IV-infix to postfix and eval.ppt dsa
PPTX
Data structures (Infix, Prefix and Postfix notations).pptx
PPT
Infix prefix postfix
PPT
Mesics lecture 4 c operators and experssions
PDF
Unit ii chapter 1 operator and expressions in c
PPTX
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
PPTX
Operators and expressions in c language
PPTX
Operators inc c language
PPTX
Lecture 6 data structures and algorithms
PPTX
Operator.ppt
PPT
cprogrammingoperator.ppt
PPT
C operator and expression
Infix to postfix
Lecture_04.2.pptx
Precedence of operators IN C PROGRAMMING
Basic operators and it's types in c languages
operator
data structure notes for engi DSA1 (2).pptx
computer notes - Evaluating postfix expressions
Arithmetic notation conversion infix to1
Unit IV-infix to postfix and eval.ppt dsa
Data structures (Infix, Prefix and Postfix notations).pptx
Infix prefix postfix
Mesics lecture 4 c operators and experssions
Unit ii chapter 1 operator and expressions in c
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
Operators and expressions in c language
Operators inc c language
Lecture 6 data structures and algorithms
Operator.ppt
cprogrammingoperator.ppt
C operator and expression
Ad

More from karmuhtam (20)

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

Recently uploaded (20)

PPTX
Pharma ospi slides which help in ospi learning
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
master seminar digital applications in india
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Pre independence Education in Inndia.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Lesson notes of climatology university.
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Pharma ospi slides which help in ospi learning
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
2.FourierTransform-ShortQuestionswithAnswers.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
STATICS OF THE RIGID BODIES Hibbelers.pdf
Sports Quiz easy sports quiz sports quiz
master seminar digital applications in india
Module 4: Burden of Disease Tutorial Slides S2 2025
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Microbial diseases, their pathogenesis and prophylaxis
O7-L3 Supply Chain Operations - ICLT Program
Pre independence Education in Inndia.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Cell Types and Its function , kingdom of life
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Lesson notes of climatology university.
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
102 student loan defaulters named and shamed – Is someone you know on the list?
O5-L3 Freight Transport Ops (International) V1.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf

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