# Test 2 CSCI 130
Summer 2004

- Please answer each question fully, carefully and thoughtfully.
- No credit will be given for unreadable answers, please write neatly.
- Answer the questions in any order, but please number each answer.
- Make sure that your name is on your test.

- (4 points) Give the syntax of the if-then-else structure
- (4 points) Describe the flow of control of the if-then-else structure
- (4 points) Give the syntax of the while structure
- (4 points) Describe the flow of control of the while structure
- (4 points) Describe the Boolean type. Give an example of
a computation that uses a boolean value. Show how to declare
a boolean variable.
- (2 points) Describe the
*and * operation.
- (3 points) What is short circuit evaluation? Give an example.
- (5 points) Write a code segment that prints the numbers 100 down to 2 in steps of 2.
- (6 points) Describe an three things that must be done with every
loop that is not infinite. Give a simple example of code and label
each part.
- (10 points) Write a segment of code that reads in 10 numbers from a
file, prints the largest, smallest and average value of the numbers.
- (4 points) The linear search algorithm is O(n), while the binary search
algorithm is O(lg n). Explain what this statement means and why one algorithm is preferable to the other.