Exam 1

Basic Approaches to Design and Analysis

CS 3530
Design and Analysis of Algorithms

Tuesday, February 11, 2014 @ 1:00 PM



  1. Design an algorithm to determine if two words are anagrams of one another, that is, whether the two words have exactly the same letters, only in a different order. For example, late is an anagram of teal. How efficient is your algorithm?

  2. For each of the following terms, say whether the term is true of your algorithm for Problem 1 and explain briefly why or why not.

  3. We have a list of 2n numbers. We would like divide the list into two sub-lists of n numbers each, L1 and L2, such that sum(L1)-sum(L2) is as large as possible.

    Design an algorithm to produce two such sub-lists. Is your algorithm top-down, bottom-up, or neither?

  4. Consider this algorithm for sorting an array:
             INPUT:  array initial[0..n-1] of values that can be ordered
             for i ← 1 to n do
               j ← i
               while j > 0 and initial[j-1] > initial[j] do
                 tmp ← initial[j-1]
                 initial[j-1] ← initial[j]
                 initial[j] ← tmp
                 j ← j - 1

    Write brief answers for each of the following:

  5. Consider this recursive algorithm, foo(n):
             if n = 0
                return 0
                return 3*foo(n-1) + 1

    Write brief answers for each of the following:

Eugene Wallingford ..... wallingf@cs.uni.edu ..... February 10, 2014