Homework Assignment 1

Introduction to Algorithms and Analysis

CS 3530
Design and Analysis of Algorithms
Spring Semester 2014

Due: Thursday, January 30, at 12:30 PM


  1. Given two sorted lists of values, we would like to find the list of common elements, also sorted. For example, given [2, 2, 3, 7] and [2, 3, 3, 3, 5, 7], the list of common elements is [2, 3, 7].

    In Session 4, we saw one algorithm for solving this problem.

  2. Consider the Comparison Counting Sort algorithm below, which appears in Levitin's text. Given an unsorted array of values, it produces a new, sorted array. It does so by counting for each item v the number of items in the array that are less than v, and using that information to put v in its appropriate spot.

  3. Read the first two paragraphs of the section labeled What is a patent? on US Patent and Trademark Office's patents web page.

    Should the inventor of an algorithm be eligible to receive a utility patent? Why, or why not? (Limit yourself to three to five sentences.)


By the due date and time, submit a hardcopy of your solutions to my mailbox in the department office, or to the front desk in our classroom before class begins.

Comparison Counting Sort

    // Input : Array A[0..n-1] of orderable values
    // Output: Array S[0..n-1] of A's elements,
    //         sorted in nondecreasing order

    for i ← 0 to n-1 do
        Count[i] ← 0

    for i ← 0 to n-2 do
        for j ← i+1 to n-1 do
            if A[i] < A[j]
               then Count[j] ← Count[j] + 1
               else Count[i] ← Count[i] + 1

    for i ← 0 to n-1 do
        S[Count[i]] ← A[i]

    return S

(This algorithm appears on Page 34 of The Design and Analysis of Algorithms by Anany Levitin. I have made a few trivial typographical changes to the presentation.)

Eugene Wallingford ..... wallingf@cs.uni.edu ..... January 23, 2014