Download presentation

Presentation is loading. Please wait.

Published byLeslie Hollis Modified over 3 years ago

1
L YNBROOK C OMPUTER S CIENCE Member Meeting, November 10, 2008

2
U PCOMING C OMPETITIONS Today: USACO November Round 11/12 (Wed): TopCoder SRM Round 12/5-12/8 (Fri-Mon): USACO December Round 12/15 (Mon): ACSL Contest #1 Check http://LynbrookCS.com for full ACSL and USACO schedules!http://LynbrookCS.com

3
T ESTED M ATERIAL ON THE ACSL What does this program do? Number Systems (different base operations) Recursive Functions (f(x) = f(x-1) + 1) Boolean Algebra (not A + B = …) Bit String Flicking (right shift, left shift) LISP Evaluation (ADD, SUB, DIV, MULT) Digital Electronics (AND, OR, XOR, NAND, NOR, XNOR) Prefix/Infix/Postfix Notation (+ 3 4) Data Structures (heaps, binary trees, stacks, etc.)

4
W HAT DOES THIS PROGRAM DO ? Usually written in an easy-to-understand language such as BASIC or Pascal Trick is to read the code as if it were in english, and then evaluate the operations as they come. program S(input, output); var a,b:integer; begin a:=0; b:=0; for a:=0 to 5 do begin b:=b+1; end; Simple evaluation leads us to b = 6

5
I NFIX N OTATION Operators are written in-between operands Exactly like normal mathematical evaluation A * ( B + C ) / D First add B to C Then multiply the result by A Then divide by D

6
P REFIX N OTATION Operators are written before their operands Trick is to group them with parenthesis, then convert into infix notation, and evaluate / * A + B C D (/ (* A (+ B C) ) D ) Infix notation: A * (B + C) / D

7
P OSTFIX N OTATION Operators are written after their operands Trick is to group them with parenthesis, then convert into infix notation, and evaluate A B C + * D / ( (A (B C +) *) D / ) Infix notation: A * (B + C) / D

8
W HAT DOES THIS PROGRAM DO ? program SR(input,output); var a,b,c,x:integer; begin b:=0; for a:=1 to 5 do begin x:=0; while x <= 5 do begin c:=5; repeat b:=b+c; c:=c-1; until c=0; x:=x+1; end; end end; What is the final value of b after SR is executed?

9
S OLUTION 1. Read code as if it were in english 2. Translate code into math ( ( 5+4+3+2+1 ) * 6 ) * 5 3. Evaluate mathematical operation = (15) * 6 * 5 =15 * 30 = 450

10
P REFIX /I NFIX /P OSTFIX N OTATION Translate the following from prefix to postfix: - + * 2 x * 3 y z

11
S OLUTION 1. Group problem with parenthesis (- (+ (* 2 x) (* 3 y)) z) 2. Translate problem into infix notation (((2 * x) + (3 * y)) - z) 3. Work backwards to translate from infix notation to postfix notation (((2 x *) (3 y *) +) z -) 2 x * 3 y * + z -

12
M ISCELLANEOUS Remember to sign in! Dont forget to turn in your check ($15, payable to Lynbrook ASB) if you havent done so already! Remember to take the USACO (ends today)! Check http://LynbrookCS.com for updateshttp://LynbrookCS.com Dont forget to review the material we covered today – it comes up on the ACSL!

Similar presentations

Presentation is loading. Please wait....

OK

Where Syntax Meets Semantics

Where Syntax Meets Semantics

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google