1 5. Abstract Data Structures & Algorithms 5.1 Data Structure Fundamentals.

Slides:



Advertisements
Similar presentations
CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
Advertisements

Stacks - 3 Nour El-Kadri CSI Evaluating arithmetic expressions Stack-based algorithms are used for syntactical analysis (parsing). For example.
Yinchong Han Linjia Jiang. Introduction There are three forms of expressions which are prefix, infix and postfix notation. The project will evaluate infix.
1 Chapter 7: Expressions Expressions are the fundamental means of specifying computations in a programming language To understand expression evaluation,
Postfix notation. About postfix notation Postfix, or Reverse Polish Notation (RPN) is an alternative to the way we usually write arithmetic expressions.
Program Elements We can now examine the core elements of programming (as implemented in Java) We focuse on: data types variable declaration and use, constants.
Chapter 7 Expressions and Assignment Statements. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Arithmetic Expressions Arithmetic evaluation.
ISBN Chapter 7 Expressions and Assignment Statements.
Stack  A stack is a linear data structure or abstract data type for collection of items, with the restriction that items can be added one at a time and.
C++ Operators CS242 COMPUTER PROGRAMMING T.Banan Al-Hadlaq.
CCSA 221 Programming in C CHAPTER 2 SOME FUNDAMENTALS 1 ALHANOUF ALAMR.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 15: Overloading and Templates.
5.1 and 5.4 through 5.6 Various Things. Terminology Identifiers: a name representing a variable, class name, method name, etc. Operand: a named memory.
Chapter 7 Expressions and Assignment Statements. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Arithmetic Expressions Arithmetic evaluation.
C H A P T E R S E V E N Expressions and Assignment Statements.
Data Structures Lecture : Stacks (Infix, Postfix and Prefix Expressions) Azhar Maqsood NUST Institute of Information Technology (NIIT)
1 Stacks Chapter 4 2 Introduction Consider a program to model a switching yard –Has main line and siding –Cars may be shunted, removed at any time.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
DATA STRUCTURE & ALGORITHMS CHAPTER 3: STACKS. 2 Objectives In this chapter, you will: Learn about stacks Examine various stack operations Discover stack.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
More with Methods (parameters, reference vs. value, array processing) Corresponds with Chapters 5 and 6.
Unit III : Introduction To Data Structures and Analysis Of Algorithm 10/8/ Objective : 1.To understand primitive storage structures and types 2.To.
Software Overview. Why review software? Software is the set of instructions that tells hardware what to do The reason for hardware is to execute a program.
Operators Using Java operators An operator takes one or more arguments and produces a new value. All operators produce a value from their.
Overloading Binary Operators Two ways to overload –As a member function of a class –As a friend function As member functions –General syntax Data Structures.
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
Expressions and Assignment Statements
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Chapter 6 Mathematical Operations. 6.1 Mathematical Expressions In mathematics this expression is valid 0 = -4y + 5 It is invalid in programming Left.
COMP Primitive and Class Types Yi Hong May 14, 2015.
1 5. Abstract Data Structures & Algorithms 5.6 Algorithm Evaluation.
Review 1 Polish Notation Prefix Infix Postfix Precedence of Operators Converting Infix to Postfix Evaluating Postfix.
Semantics (1).
Copyright © Curt Hill Stacks An Useful Abstract Data Type.
Wednesday, March 2 Homework #2 is posted Homework #2 is posted Due Friday, March 4 (BOC) Due Friday, March 4 (BOC) Program #5 is posted Program #5 is posted.
CHP-3 STACKS.
Searching Topics Sequential Search Binary Search.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
Constructs for Data Organization and Program Control, Scope, Binding, and Parameter Passing. Expression Evaluation.
Semantics(1). 2 Symantec(1)  To provide an authoritative definition of the meaning of all language constructs for: 1.Programmers 2.Compiler writers 3.Standards.
Lecture - 6(Stacks) On Data structures. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Lecture Outline What is a Stack? Array implementation of stacks Operations.
Strings A string is a sequence of characters that is treated as a single value. Strings are objects. We have been using strings all along. For example,
1 5. Abstract Data Structures & Algorithms 5.6 Algorithm Evaluation.
Expressions and Assignment Statements
Expressions and Assignment Statements
Arithmetic Expressions
Expressions and Assignment Statements
Java Primer 1: Types, Classes and Operators
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
Assignment and Arithmetic expressions
Cinda Heeren / Geoffrey Tien
Expressions and Assignment Statements
COMPUTER 2430 Object Oriented Programming and Data Structures I
Stacks Chapter 4.
PART II STACK APPLICATIONS
Operators and Expressions
Expressions and Assignment Statements
Building Java Programs
IFS410 Advanced Analysis and Design
Building Java Programs Chapter 2
Maths Unit 1 - Algebra Order of operations - BIDMAS Algebraic Notation
Cs212: Data Structures Computer Science Department Lecture 6: Stacks.
Languages and Compilers (SProg og Oversættere)
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs Chapter 2
Building Java Programs
Building Java Programs
Presentation transcript:

1 5. Abstract Data Structures & Algorithms 5.1 Data Structure Fundamentals

5.1.1 Operators and Notation

3 Operator An operator is a mathematical instruction that manipulates data, ‣ e.g. + means ‘add’, * means ‘multiply’, /, %. They are the equivalent of verbs in language.

4 Unary operator Unary operators act on a single data item, ‣ e.g. the negation operator used to represent negative numbers e.g. -4, ‣ e.g. the factorial operator, 8!, ‣ e.g. the percentage operator. [Are these not just shorthand for two dat items?]

5 Binary operators Binary operators work on two items of data, ‣ e.g. the addition operator (+), = 7 combines 3 and 4 by addition ‣ e.g. - (minus), * (multiply), / (divide), ^ (to the power of), div (whole number division), mod (divide and use remainder).

6 Operand An operand is a data item that the operators act on, ‣ e.g. in the expression y = x + 1, y, x and 1 are the operands.

7 Expression An expression is a combination of operators and operands, ‣ e.g. 3x + y = 29. The equivalent of a sentence in language.

8 Recap Operator (unary and binary) Operand Expression

9 Identifier An identifier is a label chosen by the programmer to represent an item in the program e.g. a variable, method, object or class. They should always have a meaningful name e.g. totalSalary, dayOfWeek, findAverage(), Student. You have seen the Java error message ‘identifier expected’.

10 Arguments An argument is a value passed to a method for it to act upon e.g. drawLine(2,2,10,50) has 4 arguments. setPosn(x,y) has 2 arguments, whatever the values of x and y happen to be at the time of the call. Sometimes called an actual parameter, but best to use the term argument.

11 Parameters A (formal) parameter is the variable name and type in the method definition e.g. for public int calculateAverage (int x, int y, int z) the parameters are int x, int y and int z. When the code is run, each parameter is replaced by the value of the variable, and becomes the argument of the method.

12 Parameters Note that in calling a method, no type is needed e.g. answer = average (numbers); However, in defining a method the type is needed (i.e. formal parameters) e.g. public static double average (int no1, int no2, int no3) {... etc.

13 What gets passed? Primitives (int, double, etc.) are passed-by- value i.e. the value of the argument is copied before being sent to the method and any changes to it do not affect the original variable (two different memory locations). Objects are passed-by-reference i.e. a pointer at its memory location is passed, not a copy, and any changes the called method makes change the original object.

14 Infix notation Infix notation is the usual way that we write algebraic expressions, i.e. the operator is written between the operands, e.g. ‘the sum of x and y multiplied by z is written ( x + y ) * z. It is also the usual word order in English: ‘the dog bites the man’ = noun - verb - noun.

15 Postfix notation In postfix notation, the operator is written after the operands to which it is applied, e.g. x y + z * means ‘x plus y multiplied by z’. It is a more logical order for a processor to work in and requires no brackets. It is sometimes known as reverse Polish notation (RPN). In Latin, the verb comes at the end of the sentence: ‘canis hominem mordet’.

16 Prefix notation In prefix notation, the operator comes before the operands ‣ e.g. + x y * z. It is also known as Polish notation. The processor has warning of the operator to be executed before the operands arrive. It also requires no brackets Commands in English can be prefix e.g. ‘add together x and y’.

17 Converting between notations If asked to convert a complex expression between notations, put in all implied brackets first, e.g. converting 4 * ( ) – 3 (which is infix) into postfix, insert all implied brackets: ((4 * ( )) – 3), convert each element to prefix: (- (* 4 (+ 1 2)) 3), remove the brackets: - *

18 Static vs. dynamic data structures A static data structure has its size and nature determined before a program is executed e.g. an array A dynamic data structure can vary in size to suit the data it has to contain - they are faster and more efficient to use but harder to program.