Exam 2

Algorithm Design:
Brute-Force and Top-Down


CS 3530
Design and Analysis of Algorithms


Thursday, March 13, 2014 @ 1:00 PM


Instructions



Problems

  1. Design a divide-and-conquer algorithm to compute kn for k > 0 and integer n >= 0.

  2. Answer these questions about your divide-and-conquer algorithm for Problem 1. Assume that n = 2m for some integer m.

  3. Here is an optimized implementation of insertion sort from Session 14:
         INPUT: array A[0..n-1]
    
         1  for i := 1 to n-1
         2    v := A[i]
         3    j := i - 1
         4    while j ≥ 0 AND A[j] > v
         5      A[j+1] := A[j]
         6      j := j - 1
         7    A[j+1] := v
    

    Trace this algorithm for the input [89 45 68 90 29] and write down the following information just before executing Line 7 on each pass:


  4. Consider the partition problem: Given n positive integers, partition them into two disjoint subsets such that, when we sum the elements in each subset, the two sums are equal.

  5. Suppose we are given an array A[0..n-1] of integers, in no particular order. Suppose further that we have an operator reverse(j) that can reverse the integers in slots 0 through j in a single step.

    Design a decrease-and-conquer algorithm to sort the array. Use the following invariant:

    After k steps, the largest k numbers are in their correct positions.



Eugene Wallingford ..... wallingf@cs.uni.edu ..... March 13, 2014