120 likes | 347 Views
Lynbrook Computer Science. Member Meeting, November 10, 2008. Upcoming Competitions. 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!.
E N D
Lynbrook Computer Science Member Meeting, November 10, 2008
Upcoming Competitions • 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!
Tested Material 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.)
What 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; end; • Simple evaluation leads us to b = 6
Infix Notation • 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
Prefix Notation • 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
Postfix Notation • 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
What 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?
Solution • 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
Prefix/Infix/Postfix Notation • Translate the following from prefix to postfix: • - + * 2 x * 3 y z
Solution • 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 -
Miscellaneous • Remember to sign in! • Don’t forget to turn in your check ($15, payable to Lynbrook ASB) if you haven’t done so already! • Remember to take the USACO (ends today)! • Check http://LynbrookCS.com for updates • Don’t forget to review the material we covered today – it comes up on the ACSL!