Abstract Data Types Sir Joseph Lindo University of the Cordilleras

23
Joseph Lindo Abstract Data Types Sir Joseph Lindo University of the Cordilleras

description

Abstract Data Types Sir Joseph Lindo University of the Cordilleras. Abstract Data Types. Array. Stack. ADT. All insertions and deletions are made at one end top of the stack Last In First Out (LIFO) Some analogies Stack of trays Books in a table. List. Stack. Stack. Queue. - PowerPoint PPT Presentation

Transcript of Abstract Data Types Sir Joseph Lindo University of the Cordilleras

Page 1: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

AbstractDataTypesSir Joseph Lindo

University of the Cordilleras

Page 2: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

ADT

Abstract Data Types

StackAll insertions and deletions are made at one end

top of the stackLast In First Out (LIFO)Some analogiesStack of trays Books in a table

List

Stack

Queue

Case

Array

Stack

Page 3: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

ADT

Abstract Data Types

Stack ApplicationArithmetic Expression

INFIXPREFIXPOSTFIX

List

Stack

Queue

Case

Array

Stack

Page 4: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

AbstractDataTypes

-- end --Sir Joseph Lindo

University of the Cordilleras

Page 5: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

AbstractDataTypes-- end na --Sir Joseph Lindo

University of the Cordilleras

Page 6: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

Stack in real life

Online Activity

• Think of real life activities, scenarios or things that applies the concept stack.

• Post answer as comment on our facebook group, in your specified block (F,D and G)

• You are not allowed to have the same answer

Page 7: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

Major Operations

Stack

• PUSH (Object)- add object into the top of the stack

• POP- remove object into the top of the stack

• Others- isEmpty- isFull- PEEK

Page 8: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

INFIX Notation

Stack

To add A, B, we writeA+B

To multiply A, B, we writeA*B

The operators ('+' and '*') go in between the operands ('A' and 'B')

Page 9: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

PREFIX Notation

Stack

Instead of saying "A plus B", we could say "add A,B " and write

+ A B

"Multiply A,B" would be written* A B

Page 10: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

POSTFIX Notation

Stack

Another alternative is to put the operators after the operands as in

A B +and

A B *

Page 11: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

Notations

Stack

The terms infix, prefix, and postfix tell us whether the operators go between, before, or after the operands.

Pre A In B Post

Page 12: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

Notations

Stack

Parenthesis

Evaluate 2+3*5.+ First:

(2+3)*5 = 5*5 = 25* First:

2+(3*5) = 2+15 = 17

INFIX notation requires Parentheses.

Page 13: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

Notations

Stack

What about PREFIX? + 2 * 3 5 =

= + 2 * 3 5 = + 2 15 = 17

* + 2 3 5 = = * + 2 3 5 = * 5 5 = 25

No parentheses needed!

Page 14: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

Notations

Stack

What about POSTFIX?

2 3 5 * + = = 2 3 5 * + = 2 15 + = 17

2 3 + 5 * = = 2 3 + 5 * = 5 5 * = 25

No parentheses needed here either!

Page 15: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

Notations

Stack

Conc lusion

Infix is the only notation that requires parentheses in order to change the order in which the operations are done.

Page 16: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

FPE

Stack

A FPE has exactly one set of Parentheses enclosing each operator and its operands.

Which is fully parenthesized?( A + B ) * C

( ( A + B) * C ) ( ( A + B) * ( C ) )

Page 17: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

INFIX to PREFIX

Stack

Move each operator to the left of its operands & remove the parentheses:

( ( A + B) * ( C + D ) )( + A B * ( C + D ) )

* + A B ( C + D )* + A B + C D

Order of operands does not change!

Page 18: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

INFIX to PREFIX

Stack

Practice:

1.( ( A + ( B – D ) ) * C)

2.( ( ( C * B ) / ( E + B) )/ F )

Page 19: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

INFIX to POSTFIX

Stack

Move each operator to the left of its operands & remove the parentheses:

( ( A + B) * ( C + D ) )( A B + * ( C + D ) )

A B + (C + D ) *A B + C D + *

Order of operands does not change!

Page 20: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

INFIX to PREFIX

Stack

Practice:

1.( ( A + ( B – D ) ) * C)

2.( ( ( C * B ) / ( E + B) )/ F )

Page 21: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

AbstractDataTypes

-- end --Sir Joseph Lindo

University of the Cordilleras

Page 22: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

AbstractDataTypes-- end na --Sir Joseph Lindo

University of the Cordilleras

Page 23: Abstract Data Types Sir Joseph  Lindo University of the Cordilleras

Joseph Lindo

Comprehension Check