Computer Science 3675
Fall 2017
Practice Questions for Quiz 1

  1. What is a declarative program? That is, what is its defining characteristic?

    Answer

  2. What is an important advantage of the linked representation of sequences over the sequential representation?

    Answer

  3. What is an important advantage of the sequential representation of sequences over the linked representation?

    Answer

  4. What is the difference between a strongly statically typed language and a weakly statically typed language?

    Answer

  5. What is the defining characteristic of a dynamically typed language?

    Answer

  6. What is the head of list [3,5,4,8]?

    Answer

  7. What is the tail of list [3,5,4,8]?

    Answer

  8. What is the head of list [4,2]?

    Answer

  9. What is the tail of list [4,2]?

    Answer

  10. What is a solution to pattern match equation [x, y+1] = [7, 99]?

    Answer

  11. What is a solution to pattern match equation x :: y :: z = [1, 2, 3, 4]?

    Answer

  12. Why did structured programming replace programming using gotos?

    Answer

  13. Given the definition

        f([])   = []
        f(h::t) = (h*h)::f(t)  when h > 10
        f(h::t) = f(t)         when h <= 10
    
    show an evaluation of expression f([4, 12, 15, 6, 11]) by substitution. Show the entire expression at each step. Assume that arithmetic is done as soon as possible.

    Answer

  14. Write an equational definition of a function prefix so that prefix(x, y) is true just when list x is a prefix of list y. For example, prefix([1, 2], [1, 2, 4, 6]) is true, but prefix([1, 2], [1, 5, 2, 6]) is false. It is not required that x be a proper prefix of y. So prefix([2, 3], [2, 3]) is true. The empty list is a prefix of every list.

    Answer

  15. Show an inside-out evaluation of prefix([1, 2], [1, 2, 3, 4]) using your definition of prefix from the preceding question. Show the entire expression at each step.

    Answer

  16. Write an equational definition of longestCommonPrefix(x, y), which yields the longest list that is a prefix of both x and y. For example, longestCommonPrefix([2, 5, 3, 9, 5], [2, 5, 2, 9, 5]) = [2, 5].

    Answer

  17. Show an inside-out evaluation by substitution of longestCommonPrefix([2, 5, 3, 9, 5], [2, 5, 2, 9, 5]). Show the entire expression at each step.

    Answer