Test 2 CSCI 130 Summer 2004


  1. (4 points) Give the syntax of the if-then-else structure
  2. (4 points) Describe the flow of control of the if-then-else structure
  3. (4 points) Give the syntax of the while structure
  4. (4 points) Describe the flow of control of the while structure
  5. (4 points) Describe the Boolean type. Give an example of a computation that uses a boolean value. Show how to declare a boolean variable.
  6. (2 points) Describe the and operation.
  7. (3 points) What is short circuit evaluation? Give an example.
  8. (5 points) Write a code segment that prints the numbers 100 down to 2 in steps of 2.
  9. (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. (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.
  11. (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.