Course Home | Assignments | Schedule & Lecture Notes

Saint Louis University

Computer Science 3100
Algorithms

Michael Goldwasser

Fall 2016

Dept. of Computer Science

Homework Assignment 01

Introduction, Asymptotics, Divide and Conquer


Overview

Topics: review
Related Reading: Chapters 1, 2, 3, 8, and 10 of CLRS
Due: 10:00am, Wednesday, September 7, 2016

You must adhere to the policies on academic integrity, paying particular attention to the limits on collaboration.


Problems to be Submitted

NOTE: This assignment will be worth 100 points. Each problem is worth 25 points and I will give you credit for the highest four scores on the five problems. So if you wish to simply turn in four of the five, then those will be the four I grade. But if you attempt all five, then you'll get your best four scores.
  1. Work entirely on your own

    Problem 2-1 (starting on page 39 of CLRS)

  2. Work entirely on your own

    Problem 8-6 (on page 208 of CLRS)

  3. Work entirely on your own

    Exercise 10.3-4 (on page 245 of CLRS). To be sufficiently rigorous, your solution should include complete pseudocode, using the style of that chapter, and an explanation regarding the correctness and efficiency of your solution. Although not stated in the book's problem, it is important that both of your operations still run in O(1) time. I'd also like to note that I find the book's hint about an "array implementation of a stack" to be more misleading that it is useful. I suggest ignoring that entirely.

    Finally, please note that you are not responsible for reimplementing the linked-list operations LIST-INSERT and LIST-DELETE from section 10.2. You are just responsbile for designing the FREE and ALLOCATE methods that might be used by those routines for proper memory management.

    As an example, if a linked list had contents S-A-M-P-L-E (assuming character data), a representation might be the following:

    index: 1 2 3 4 5 6
    
    next:  6 5 1 2 - 4
    key:   A L S P E M
    prev:  3 4 - 6 2 1
    
    if the letter L were removed from the list, the LIST-DELETE code would make the linked list changes to splice the neighboring P and E together, while no longer using node 2, resulting in
    index: 1 2 3 4 5 6
    
    next:  6 - 1 5 - 4
    key:   A - S P E M
    prev:  3 - - 6 4 1
    
    At this point that code should call FREE(x) where x is the newly unused node stored at index 2. Your job is to decide how to implement FREE( ) in such a scenario so that by the time you finish, the representation is compact (and the user's linked list remains valid).

    In similar regard, if a user wished to add another node to their list, your job with ALLOCATE( ) is to return the location of the new node; you do not need to concern yourself with how that new node becomes encorporated in the list after it is allocated.

  4. You may discuss ideas with other students (but your writeup must be independent)

    Exercise 10.2-8 (on page 241 of CLRS). To be sufficiently rigorous, your solution should include complete pseudocode, using the style of that chapter, and an explanation regarding the correctness and efficiency of your solution.

  5. You may discuss ideas with other students (but your writeup must be independent)

    Assume that we have a sequence of n numbers containing all the integers from 0 to n except one, in arbitrary order. The goal is to efficiently determine which number is missing. However, the numbers are represented in binary. For example, the input for n=5 might be modeled as:
    101
    011
    010
    000
    001
    By the way, in this example, the missing number is 4.

    In solving the problem, you will be charged for each bit of the input that is examined. Therefore, at the beginning of the process for a given n, the unknown input might be viewed as follows:
    ???
    ???
    ???
    ???
    ???
    Note that the input to the algorithm consists of an array of n numbers, each of which is comprised of ⌊lg n⌋+1 bits.

    Describe an algorithm that finds the missing number while fetching O(n) bits. Make sure to justify its correctness and analysis.


Extra Credit

  1. Problem 4-5 (starting on page 109 of CLRS)


Michael Goldwasser ©2016
CSCI 3100, Fall 2016
Last modified: Monday, 05 September 2016
Course Home | Assignments | Schedule & Lecture Notes