Computer Science 3675
Fall 2015
Practice Questions for Quiz 2

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

    Answer

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

    Answer

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

    Answer

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

    Answer

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

    Answer

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

    Answer

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

    Answer

  8. What is 3::[5,4]?

    Answer

  9. 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

  10. 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

  11. 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

  12. Write an equational definition of function numEven(L), which returns the number of even numbers in list-of-integers L. For example, numEven([2,3,4,5,6]) = 3. Assume that isEven(n) is true if n is even, false if n is odd.

    Answer