SUNY Geneseo, Department of Computer Science


Sample Questions for Exam 1

CSci 141 , Fall 2003

Prof. Doug Baldwin

The questions below were the first hour exam last time I taught CSci 141. Because of differences in course pace, lecture and laboratory examples, etc. these aren't necessarily exactly like the questions I will ask this time, but they should give you some sense of what to expect.

Question 1

Write (pseudocode is fine) a recursive algorithm that computes xn, for any real number x and natural number n. Your algorithm should take x and n as parameters.

Question 2

Here is an algorithm that prints a sequence of letters:

    printChars( int n )
        if n > 1
            print “aa”
            printChars( n – 1 )
            print “bbb”
        else
            print “c”

Derive the number of letters this prints, as a function of n.

Question 3.

Suppose you are using a clock function with a resolution of 1 millisecond to measure how long some operation in a program takes. You make 10 separate measurements of the operation (all made under as nearly identical conditions as possible), and get the following times:

1, 2, 2, 1, 2, 2, 2, 1, 2, 1

Part A

What would you give as the time for this operation, and why?

Part B

What do you think is the main source of error in these measurements? Is it a random error or a systematic one?