L-43 MCS 260 Fri 28 Nov 2001

Review Questions III for Final Exam

The questions below are meant to stimulate the preparation of the final exam. They cover some of the most important but not all topics in the course. You must review all course materials: textbook, exercises, lecture notes, quizzes, and exams.

  1. Suppose we have a large array of data and wish to see how the data are distributed.
         void distribute ( int N, float data[], int m, float freq[], int h );
         /* on return, the array freq contains the following m numbers :
              freq[0] counts the numbers in data less than zero,
              freq[1] counts the numbers in data less than h, and >= 0,
              freq[2] counts the numbers in data less than 2*h, and >= h,..,
              freq[i] counts the numbers in data less than i*h, and >= (i-1)*h,..,
              freq[m-1] counts the numbers in data >= (m-2)*h. */
    
    Give a definition for distribute.

  2. Consider the following function:
           int count_occurrences ( int n, char s[], char c );
           /* returns number of occurrences of c in s */
    
    For example, if s = { 'l','a','s','t',' ','d','a','y' }, then int_occurrences(8,s,'a') returns two.
    1. Give a definition of count_occurrences.
    2. Replace all brackets in your definition above by the equivalent instructions with pointers. Give the equivalent prototype and definition of count_occurrences, using only pointers.
  3. Consider the following function:
           double max ( int n, double *a );
           /* returns the maximal value in the array a */
    
    1. Give a definition of max, without brackets, using only pointers.
    2. Replace all pointers in your definition above by equivalent instructions with brackets. Give the equivalent prototype and definition of max avoiding the use of pointers.
  4. Give a definition for the following function:
           double dotprod ( int n, double x[], double y[] );
           /* returns the sum of the elements in x componentwise
              multiplied with those in y */
    
    Change the prototype and rewrite you definition using only pointers.
  5. Give a definition for the following function:
           float *multiply ( int n, int m, float *a, float *x );
           /* multiplies the nxm-matrix a with the m-vector x */
    
    You must allocate memory for the result.

FINAL EXAM is in Lecture Center C6 on Monday 3 December 2001 from 1:00 till 3:00PM.

Please let me know as soon as possible if you cannot attend the exam and need to schedule a makeup.

Incomplete grades are only given in exceptional cases. At least the two following conditions must be satisfied: the student is in good standing (has decent scores on midterm exams, projects, and quizzes) and the student is unable to take an exam during the finals week.