1 / 23

Abstract Data Types Sir Joseph Lindo University of the Cordilleras

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.

yair
Download Presentation

Abstract Data Types Sir Joseph Lindo University of the Cordilleras

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Abstract Data Types Sir Joseph Lindo University of the Cordilleras

  2. 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 Case

  3. Abstract Data Types Array Stack Application ADT Arithmetic Expression INFIX PREFIX POSTFIX List Stack Stack Queue Case

  4. Abstract Data Types -- end -- Sir Joseph Lindo University of the Cordilleras

  5. Abstract Data Types -- end na -- Sir Joseph Lindo University of the Cordilleras

  6. Online Activity Stack in real life • 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

  7. Stack Major Operations • PUSH (Object) • - add object into the top of the stack • POP • - remove object into the top of the stack • Others • isEmpty • isFull • PEEK

  8. Stack INFIX Notation To add A, B, we write A+B To multiply A, B, we write A*B The operators ('+' and '*') go in between the operands ('A' and 'B')

  9. Stack PREFIX Notation Instead of saying "A plus B", we could say "add A,B " and write + A B "Multiply A,B" would be written * A B

  10. Stack POSTFIX Notation Another alternative is to put the operators after the operands as in A B + and A B *

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

  12. Stack Notations Parenthesis Evaluate 2+3*5. + First: (2+3)*5 = 5*5 = 25 * First: 2+(3*5) = 2+15 = 17 INFIX notation requires Parentheses.

  13. Stack Notations What about PREFIX? + 2 * 3 5 = = + 2 * 3 5 = + 2 15 = 17 * + 2 3 5 = = * + 2 3 5 = * 5 5 = 25 No parentheses needed!

  14. Stack Notations 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!

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

  16. Stack FPE 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 ) )

  17. Stack INFIX to PREFIX 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!

  18. Stack INFIX to PREFIX Practice: ( ( A + ( B – D ) ) * C) ( ( ( C * B ) / ( E + B) )/ F )

  19. Stack INFIX to POSTFIX 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!

  20. Stack INFIX to PREFIX Practice: ( ( A + ( B – D ) ) * C) ( ( ( C * B ) / ( E + B) )/ F )

  21. Abstract Data Types -- end -- Sir Joseph Lindo University of the Cordilleras

  22. Abstract Data Types -- end na -- Sir Joseph Lindo University of the Cordilleras

  23. Comprehension Check

More Related