merican Computer cience eague 1996í97 ll-tar Contest olutions Round è1 1. The answer shown is the only correct answer. 2*è*B-CèDè 2. The expression is

Similar documents
Math 241: Calculus III Final Exam è300 points totalè Show All Work Name This test consists of 2 parts. There are 10 problems in Part I, each worth 18

PART I. Answer each of the following. è1è Let! u = h2;,1;,2i and! v = h3; 1;,1i. Calculate: èaè! u, 2! v èbè the dot product of! u and! v ècè! u æ! v

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

The PCAT Programming Language Reference Manual

19.2 View Serializability. Recall our discussion in Section?? of how our true goal in the design of a

Inænitely Long Walks on 2-colored Graphs Which Don't Cover the. Graph. Pete Gemmell æ. December 14, Abstract

æ additional rules in s to recognize terminals For each x2æ, g2,, ès,xgè 2 æès,x,gè This is called a shift operation. æ pop S from stack and move into

bè ëfind all countries C and the sum S of all of C's city populations, provided S is at least 10,000,000", SUMèPopulationè GROUP BY Co Name HAVING SUM

7/25/2016. Example: Addition of Unsigned Bit Patterns. ECE 120: Introduction to Computing. Adding Two Non-Negative Patterns Can Overflow

Math 96--Radicals #1-- Simplify; Combine--page 1

PYTHON- AN INNOVATION

More Assigned Reading and Exercises on Syntax (for Exam 2)

FAST IEEE ROUNDING FOR DIVISION BY FUNCTIONAL ITERATION. Stuart F. Oberman and Michael J. Flynn. Technical Report: CSL-TR

School of Computing National University of Singapore CS2010 Data Structures and Algorithms 2 Semester 2, AY 2015/16. Tutorial 2 (Answers)

where ëvar" represents a variable and ëint" represents an integer. The productions are numbered. Grammar for CAMO: In shorter notation èmostly use ærs

The SPL Programming Language Reference Manual

CMSC 313 Lecture 03 Multiple-byte data big-endian vs little-endian sign extension Multiplication and division Floating point formats Character Codes

6.1 Combinational Circuits. George Boole ( ) Claude Shannon ( )

ACSL All-Star Practice, Woburn CI, (T AR) + S R = ART S + ST + AR

rate name People Consult Topics name rate name People Consult Topics name

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

A Java program contains at least one class definition.

Name: 2 Useful Formulas Pn i=1 i = nèn+1è 2 Pn i=1 xi = xn+1,1 x,1 P Pn 1 =lnn + Oè1è 1 i=1 i i=0 = ixi x è1,xè 2 e x =1+x + x2 + x 3 2! 3! + ::: lim

CIS-331 Spring 2016 Exam 1 Name: Total of 109 Points Version 1

Chapter 3. Gate-Level Minimization. Outlines

2/5/2018. Expressions are Used to Perform Calculations. ECE 220: Computer Systems & Programming. Our Class Focuses on Four Types of Operator in C

COMP Primitive and Class Types. Yi Hong May 14, 2015

2.6 BOOLEAN FUNCTIONS

CS 320: Concepts of Programming Languages

where C is traversed in the clockwise direction, r 5 èuè =h, sin u; cos ui; u ë0; çè; è6è where C is traversed in the counterclockwise direction èhow

ACSL All-Star Practice

CSc 520 Principles of Programming Languages. 26 : Control Structures Introduction

The ray tracing software package implements an object-oriented approach to

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

II. Language Processing ystem skeletal source program preprocessor source program compiler target object assembly program assembler relocatable machin

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

DKT 122/3 DIGITAL SYSTEM 1

Introduction. The Quine-McCluskey Method Handout 5 January 24, CSEE E6861y Prof. Steven Nowick

2008 The McGraw-Hill Companies, Inc. All rights reserved.

LECTURE 17. Expressions and Assignment

COSC 320 Exam 2 Key Spring Part 1: Hash Functions

BITWISE OPERATORS. There are a number of ways to manipulate binary values. Just as you can with

Practical Questions CSCA48 Winter 2018 Week 11

Lecture 4 CSE July 1992

CIS-331 Fall 2013 Exam 1 Name: Total of 120 Points Version 1

Medium Term Plan Year 6: Autumn Term

CmpSci 187: Programming with Data Structures Spring 2015

Logic Design: Part 2

Lesson 38: Conditionals #2 (W11D3)

Arithmetic and Bitwise Operations on Binary Data

ECE550 PRACTICE Midterm

A simple syntax-directed

Operators And Expressions

8. An example row consists of constants and example elements which are really domain variables.

CSCI 111 First Midterm Exam Fall Solutions 09.00am 09.50am, Wednesday, October 18, 2017

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Medium Term Plan Year 4

This book is licensed under a Creative Commons Attribution 3.0 License

Combinational Logic & Circuits

CSE332 Summer 2010: Final Exam

Read this before starting!

CS Bootcamp Boolean Logic Autumn 2015 A B A B T T T T F F F T F F F F T T T T F T F T T F F F

ACSL All-Star Practice

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, FALL 2012

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

Here is a C function that will print a selected block of bytes from such a memory block, using an array-based view of the necessary logic:

[Y2] Counting and understanding number. [Y2] Counting and understanding number. [Y2] Counting and understanding number

Midterm Solutions COMS W4115 Programming Languages and Translators Wednesday, March 25, :10-5:25pm, 309 Havemeyer

Gate Level Minimization Map Method

CSE 452: Programming Languages. Outline of Today s Lecture. Expressions. Expressions and Control Flow

Here is a C function that will print a selected block of bytes from such a memory block, using an array-based view of the necessary logic:

Declaring Numbers. Bernd Braßel, Frank Huch and Sebastian Fischer. Department of Computer Science, University of Kiel, Germany

CSL 201 Data Structures Mid-Semester Exam minutes

Bits, Words, and Integers

CSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Haskell Functions

Prof. Navrati Saxena TA: Rochak Sachan

Summary of Course Coverage

Chapter 7. Expressions and Assignment Statements ISBN

1. Fill in the entries in the truth table below to specify the logic function described by the expression, AB AC A B C Z

APPLESHARE PC UPDATE INTERNATIONAL SUPPORT IN APPLESHARE PC

PCL Greek-8 - Code Page 869

Algebra 1 Summer Review Packet DUE THE FIRST DAY OF SCHOOL

æ When a query is presented to the system, it is useful to ænd an eæcient method of ænding the answer,

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators

Chapter 1 Preliminaries

IT 201 Digital System Design Module II Notes

Comp 150 Final Exam Overview.

Binary, Hexadecimal and Octal number system

MML Contest #1 ROUND 1: VOLUME & SURFACES

CS 5515 Fall Solution to Test è1. Open booksènotes; calculator allowed

Conditionals !

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. Numbers & Number Systems

Lecture 1. Types, Expressions, & Variables

DIGITAL SYSTEM DESIGN

SWITCHING THEORY AND LOGIC CIRCUITS

CS 275 Automata and Formal Language Theory. First Problem of URMs. (a) Definition of the Turing Machine. III.3 (a) Definition of the Turing Machine

Chapter 4. Combinational Logic. Dr. Abu-Arqoub

CS345 Midterm Examination. Wednesday, May 14, 2003, 9:30 í 11:30AM. Directions. The exam is open book; any written materials may be used.

Architecture of Compilers, Interpreters. CMSC 330: Organization of Programming Languages. Front End Scanner and Parser. Implementing the Front End

Transcription:

Name: chool: Div: ID: 1996í97 ll-tar Contest hort Problems Round è1 eave this box blank! 1. ëjrë BIC Expressions Write a BIC expression that is an exact translation of the following: Twice the diæerence of the product of and B and the quotient of C and D Use the fewest number of parentheses as possible. 2. ëjr, Int, rë Boolean lgebra ist all of the following choices that are equivalent to the expression è æ Bèè + Bèè + Bè èaè æ B èbè + B ècè B èdè + B èeè æ B 3. ëint, rë What Does This Program Do If the following program prints the number 9 when it is run, list all possible integer inputs to the program. 10 input : B=3 : C=1 20 if èé=bè and èècéè or èbécèè then = +2 30 if èébè and èbécè then = +C 40 if èèécè and èébèè or èbécè then = -C 50 if é5 then =+2 else =+5 60 print 70 end 4. ëint, rë PreæxèPostæxèInæx Notation et è represent the unary operation ëgreatest integer less than or equal to the value of its operand." For example, the postæx expression 26 3 è è has a value of 8. Evaluate the following preæx expression: + è è * 2 3 4 è è - 1 3 è è - æ 6 2 4 6

merican Computer cience eague 1996í97 ll-tar Contest olutions Round è1 1. The answer shown is the only correct answer. 2*è*B-CèDè 2. The expression is simpliæed by applying DeMorgan's aw twice and then the deænition of XOR: è æ Bèè + Bèè + Bè =è æ Bèèè + Bè+è + Bèè =èæbèèè æ Bè+èæ Bèè =èæbèèèbè+èbèè =èæbèè æ Bè =èæbè èeè The only choice equivalent to æ B is choice èeè. 3. We can solve this program by trying small values, say between,10 and 10, looking for inputs that cause the program to print 9. If you follow this approach, you need to be able to convince yourself that all values less than,10 and greater than 10 won't work. lternatively, work backwards, one line at a time: ine 50: fter this line is executed, must have avalue of 9. If the then were executed, must have started out equal to 7. If the else were executed, must have started out with a value of 4. ine 40: fter this line is executed, must have avalue of 4 or 7. The then is always executed because BéC. Thus, must have started out with avalue of 5 or 8. 3, 5, and 8 ine 30: fter this line is executed, must have avalue of 5 or 8. If the then were executed, then must have started out equal to 4 or 7. But these are both impossible, because must be less than B. Therefore, the then was not executed, and started out with a value of 5 or 8. ine 20: fter this line is executed, must have a value of 5 or 8. Consider a ænal value of 8. If the then were executed, started out with a value of 6. But this is impossible, since must be less than B; thus started out equal to 8. Consider a ænal value of 5. If the then were executed, then started out with a value of 3. This is OK. If the then were not executed, then start out with a value of 5. This is also OK. 4. The evaluation is as follows èa box is put around the part of the expression that is about to be evaluatedè: + è è * 2 3 4 è è - 1 3 è è - æ6 2 4 6 + è è 6 4 è è -2 è è - 36 4 6 + è 1.5 è -2 è è 32 6 + 1 è -2 è 5.333....6 the fraction 3è5 is also acceptable + 1 è -2 5 + 1 -.4.6

Name: chool: Div: ID: 1996í97 ll-tar Contest hort Problems Round è2 eave this box blank! 5. ëjrë What Does This Program Do When the following program is run, the string ëhi mom!" is printed three times. Find all integer values that could be given as input. 10 input x : y = 7 20 if èx é 2è and èy é xè then print "hi mom!" 30 if èx é yè or èx é 5è then print "hi mom!" 40 if èx éé 0è and èx*x é 5è then print "hi mom!" 50 end 6. ëjr, Int, rë Digital Electronics Find all ordered triples that make the circuit below true. B C 7. ëint, rë Pascal fter the following program is run, what is the ænal value of a program lltar97; var a, b, c: integer; procedure two èvar c, b, a: integerè; begin a:=a-2; b:=b-1; c:=a+b; end; procedure one èvar a, b, c: integerè; begin a:=a-1; b:=b-1; c:=a+b; twoèa,b,cè; end; begin a:=20; b:=10; c:=0; while a é 0 do begin oneèa,b,cè; c:=c+1; end; end. 8. ëint, rë isp Evaluate the following expression: ècr èrevere ècdr ècdr 'èè1 2è è3 4è è5 6 7èèèèèè

merican Computer cience eague 1996í97 ll-tar Contest olutions Round è2 5. In order for the string to be printed three times, it must be printed in lines 20, 30, and 40. From line 20, x =1; 0;,1;,2;::: will cause the string to be printed. ll of these values will cause line 30 to print the string. In line 40, both clauses of the if must be true for the string to be printed. The clause xéé0 eliminates 0 from the possible values of x. The clause x*xé5 is true only when x=1,,1, and,2. 1,,1, and,2 6. The circuit can be represented by the Boolean lgebra expression èè æ BèèB + Cèè We could construct a truth table for this expression, but because it's an ND of three terms, it's worth trying to reason about it. The term means that must be true. This gives us 4 possible triples to consider: è1,0,0è, è1,0,1è, è1,1,0è, and è1,1,1è. The term æ B means that and B must be diæerent. This leaves just è1,0,0è and è1,0,1è. The term B + C means than either B or C must be true. This leaves just è1,0,1è. è1,0,1è 7. The table at the right shows the values of variables just after c is incremented in the main loop. a b c 34 8 27 44 6 39 50 4 47 52 2 51 50 0 51 44,2 47 34,4 39 20,6 27 2,8 11,20,10,9,20 8. The evaluation goes from the inside to the outside: ècdr 'èè1 2è è3 4è è5 6 7èèè è èè3 4èè5 6 7èè ècdr 'èè3 4è è5 6 7èèè è èè5 6 7èè èrevere 'èè5 6 7èèè è èè5 6 7èè ècr 'èè5 6 7èèè è è5 6 7è è5 6 7è

Name: chool: Div: ID: 1996í97 ll-tar Contest hort Problems Round è3 eave this box blank! 9. ëjr, Intë Computer Number ystems Express the square of 878 16 in base 16. 10. ëjr, Int, rë Bit tring Flicking Find all values of x, 5 bits long, that make the following expression equal to 10100. èhift-2 è10101 OR xèè XOR èrcirc-2 è11011 ND ècirc-2 xèèè 11. ëint, rë Recursive Functions Evaluate f è22è given the following: fèxè = 8 é é: x + fèx +3è whenever x is prime and larger than 2 x æ fèx, 5è whenever x is even 2 x +1 otherwise 12. ërë Data tructures If you built a binary search tree with the keystkeèin this orderè, you'd end up with a tree whose internal path length is 18. uppose that you could swap up to 2 pairs of letters èe.g., the with the ærst and the T with the Kè to insert the letters in a diæerent order èe.g., KTE,using the 2 swaps aboveè. What is the minimum internal path length a resulting tree could have

merican Computer cience eague 1996í97 ll-tar Contest olutions Round è3 9. We could convert the number to base 10, square it, and then convert back to base 16. lternatively, we could do all the multiplication in base 16. We'll do the latter, but take advantage of the fact that to make the multiplication simple. èa + bè 2 = a 2 +2ab + b 2 878 2 = è800 + 78è 2 = 800 2 +2æ 800 æ 78 + 78 2 = 400000 + 1000 æ 78 + 78 2 = 400000 + 78000 + 78 2 = 478000 + 78 2 47B840 16 78 2 =è70+8è 2 =70 2 +2æ70 æ 8+8 2 = 3100 + 700 + 40 = 3840 Finally, 478000 + 3840 = 47B840. 10. Write x as abcde and simplify each side: eft side of XOR: èhift-2 è10101 OR abcdeèè èhift-2 1b1d1è 1d100 Right side of XOR: èrcirc-2 è11011 ND ècirc-2 abcdeèèè èrcirc-2 è11011 ND cdeabèè èrcirc-2 cd0abè abcd0 Now, these two values XOR'd together must equal 10100. That is, XOR abcd0 = 10100. ook at each bit, from left-to-right: 1d100 00000 and 00001 the term 0000* is also acceptable 1 XOR a = 1 implies a=0 d XOR b = 0 implies b=d 1 XOR c = 1 implies c=0 0 XOR d = 0 implies d=0, and thus b=0 11. The evaluation is as follows: fè22è = 22=2 æ fè17è = 11 æ fè17è fè17è = 17 + fè20è fè20è = 20=2 æ fè15è = 10 æ fè15è fè15è = 16 1947 Working backwards, we have f è20è = 10æ16 = 160, f è17è = 17+160 = 177, and fè22è = 11 æ 177 = 1947. 12. The shortest internal path length occurs when the binary tree is a complete tree. With 8 nodes, the shortest internal path length is 13. uch a tree can be formed with just one swap: the K and the. èother exchanges will also produce a tree whose internal path length is 13.è 13

Name: chool: Div: ID: 1996í97 ll-tar Contest hort Problems Round è4 eave this box blank! 13. ëint, rë ssembly anguage What is the ænal value of C when the following program is run DC 2 B DC 50 C DC 0 TOP OD C DD =1 TORE C OD UB B TORE B UB BG END C TOP 14. ëint, rë Fs and Regular Expressions How many diæerent strings of length 5 are generated by the following regular expression: èww+è æ C æ 15. ëint, rë Data tructures Insert the nodes T KEinto a minimal heap. That is, a heap where each node is less than or equal to its two children. èthis is diæerent than the heap described in the C Category Description booklet, where nodes were greater than their children.è Draw the resulting heap.

merican Computer cience eague 1996í97 ll-tar Contest olutions Round è4 13. The high-level program equivalent to the program is as follows: = 2 B = 50 C = 0 TOP: C = C + 1 B = B - IF B-C é 0 THEN GOTO TOP END The following table shows the values of B and C just before the BG is executed: B C 48 1 46 2 44 3...... 20 15 18 16 16 17 17 14. ll strings must end with an and must contain a C. Between the C and, there are zero or more 's. Before the C, there's either nothing, or some combination of and WW, for instance WW,, or WW. The complete list of 5-letter strings are as follows: C, C, C, C, WWC, WWC, and WWC. 7 15. Here's what the tree looks like after each letter is added: T E K T T T T K