Midterm Practice | CS 4, Summer 2007



  1. Write a complete web page that generates the following (assume that the image name is robot.jpg):



  2. Briefly describe what each of the following HTML tags does:
  3. Which of the above tags requires a closing tag?

  4. Recall the algorithm for finding the maximum number in a list of unique numbers, A1,A2,...,An. Rewrite this algorithm to find the minimum number in the list. You should print the minimum element and its position in the list.

  5. Write an algorithm that reads in 10 pairs of numbers (A1,B1), (A2,B2), ... (A10,B10). Each pair of numbers corresponds to the basketball score between teams A and B. For team A, your algorithm should compute and print the total number of wins, loses and ties. Your solution must use a for loop to read in the numbers, and compute the wins, loses, and ties.

  6. Consider adapting the sequential search algorithm to a N x N grid (a 3 x 3 is shown below). This algorithm starts searching for an element in the top left corner of the grid. The grid is scanned from left to right and top to bottom until an element is found. When an element is found, the algorithm stops.
    3 6 1
    9 8 4
    2 5 7
    For a N x N grid, how many comparisons are made in this algorithm in (give a brief explanation for your answer): (a) the best case (b) the worst case

  7. I give you an algorithm that on average requires N3 steps to execute. I then give you three more algorithms that compute the same thing and take 4N, 2N, and log(N) steps to execute. For a very large value of N, order these four algorithms from slowest to fastest.

  8. Write a javascript function RandArray that initializes an array with 100 elements, fills this array with a random integer in the range 0 to 10. Use, of course, a for loop to do this. Using another for loop, compute the number of 0's that are in this array.

  9. Write a complete web page that consists of a button, three check boxes, and a text window. The button should be labeled "done". The numbers 1,2,3 should be placed next to the check boxes. When the button is pushed a javascript function should be called that computes how many checkboxes were selected and writes that number in the text window. You may layout the button, checkboxes, and text window in any order.