CS 401 / MCS 401 Home Page     
Summer, 2007


CS 401 / MCS 401 is an advanced undergraduate course on computer algorithms.  Although many of the algorithms covered in this course are used heavily in computer programs, and some have been incorporated into programming libraries, MCS 401 / CS 401 is not itself a programming course; no programming assignments will be given.  The course covers general techniques for designing computer algorithms, as well as specific algorithms for a number of important computations (sorting, searching, shorted paths in graphs, etc.).  The objectives of the course are

Students are expected to have a reasonable knowledge of a computer language (preferably C, C++, or Java), a course on data structures, and a background in calculus, discrete mathematics, and very elementary statistics.


bullet

Organization of course 
bullet

General information  (textbook, exam dates, grading, etc; requires Adobe Acrobat Reader) 

bullet

Detailed syllabus  (requires Adobe Acrobat Reader)

bullet

Homework Assignments (from textbook, unless otherwise indicated)   
bullet

Exercise Set #1  (due Wed, Jun 6)    
bullet

Exercise 1.2-2  (page 13).  

bullet

Exercise 1-1  (page 13).  Omit the first two functions (lg(n) and sqrt(n), and then fill in the 1-minute, 1-day, and 1-year columns only. 

bullet

Exercise 3.1-4  (page 50). 

bullet

A.   Show how to compute a125 (mod m) with 11 modular multiplications, making use of the fast exponentiation algorithm discussed in class?  Be sure to indicate exactly where each multiplication occurs.  

bullet

 B.   Show how to compute b5 (mod m) using 3 modular multiplications.  Noting that 125 = 53,  and show how to compute a125 (mod m) with 9 modular multiplications.  (Your result will demonstrate that fast exponential algorithm given in class is not always optimal with regard to the number of multiplications.)
 

bullet

Exercise Set #2  (due Friday, Jun 15)  
bullet

Exercise 3-2  (page 58).  You make use of the facts proven in class about the relative rates of growth of logarithms, polynomials, and exponentials in this problem, as well as in other problems.  

bullet

Exercise 3-3, part (a)  (page 58).  Omit the functions containing lg*.  

bullet

Exercise 3-4, parts (c) and (d)  (page 59).      

bullet

C.  Use Stirling's Formula to obtain a good estimate of the value of 32! (40 factorial).  Then include the 1 + 1/(12n) term to obtain an even better estimate.  Write your answers in scientific notation, with enough decimal places shown to distinguish to two estimates.  

bullet

Page 36, exercise 2.3-1 

bullet

D.  Prove by induction on n that the recurrence
                  C(n) = d + C(k) + C(n
-k-1),  where d is a constant and  0 < k <= n-1, C(0) = 0,
has solution C(n) = dn.     

bullet

E.  Find a solution to each recurrence below that is exact when n is a power of 2, and a good approximation otherwise.  
       a)   C(n) = C(n/2) + 2n + 3,  C(1) = 1.  
       b)   C(n) = 2C(n/2) + n
lg(n),  C(1) = 0.
       c)   C(n) = 4C(n/2) + 3n2, C(1) = 0.    

bullet

Page 86, Exercise 4.4, parts (a), (c), (e), (h). 
(For those parts where the Master Theorem, or the extension to the Master theorem given in class, is applicable, quote it to obtain a solution of the form T(n) = THETA(g(n)) where g(n) is some simple function of n.  When you quote the Master theorem, give the values of a, b, E = logb(a), and f
(n); see page 73 of the text, or the handout on the Master Theorem.).  If the Master Theorem is not applicable, solve the recurrence directly, again obtaining a solution of the form T(n) = THETA(g(n)).

 

bullet Exercise Set #3 (due Wednesday, Jun 20)    
bullet

How many inversions are there in the array
                  a = (41  16  74  33  66  54)?
How many comparisons would straight insertion sort perform in sorting this array?  How many exchanges would it perform?   

bullet Exercise 6.1-6   
bullet Exercises 6.3-1 and 6.3-2   
bullet Exercises 6.4-1   (As in Fig 6.4, start with the heap just after is has been constructed by build-max-heap.  You may limit yourself to illustrating the first three steps, where one step consists of removing the root from the heap and then restoring the remaining elements to a heap.)   
bullet Exercise 6.5.7    
bullet

F.  How many inversions are there in the array
                  a = (41  16  74  33  66  54)?
How many comparisons would straight insertion sort perform in sorting this array?  How many exchanges would it perform?                                    

bullet G.  Consider the recurrence  
                  C(n) = C(0.8n) + C(0.5n) + C(0.2n) + n,  C(1) = 1.  
If the recurrence has a solution of the form
                  C(n) = a
nb + c n + d     
for some real numbers a, b, c, and d (ignoring the fact that 0.8n, 0.5n, and 0.2n may not be integers), what must the value of b be?  Compute your answer to two decimal places.      
bullet H.  Show how to merge three sorted arrays of length n/3 into a single sorted array of length n using close to 5/3n comparisons, even in the worst case.      
bullet

I.  Consider 3-way mergesort, in which an array of size n is divided into three subarrays of equal size, and the three subarrays are sorted by recursive calls to 3-way mergesort.  The recurrence for the number of comparisons becomes  C(n) = 3C(n/3) + (5/3)n, C(1) = 0, assuming n is a power of 3, say n = 3k.  Find an exact solution to this recurrence, when n is a power of 3.  (Your final solution should involve only n, not k.)  How does the number of comparisons performed by 3-way mergesort compare to the number performed by ordinary mergesort?
 

bullet

Exercise Set #4 (due Wednesday, Jun 27)

bullet Exercise 8.1-1.   
bullet Exercise 8.1-3.   
H.  Illustrate the process of partitioning the array
           36  83  75  48  14  71  64  22  91  69  58  88  72 
using the "one-sided" partitioning algorithm on page 146 of the textbook.  See Figure 7.1. 
bullet I.  Illustrate the operation of the partitioning algorithm presented in class (see quicksort handout) to partition the array
           36  83  75  48  14  71  64  22  91  69  58  88  72 
using the middle element (64) as the pivot element. 
bullet Illustrate the entire selection algorithm (the one that runs in expected linear time) for finding the 9th smallest element of the array 
           36  83  75  48  14  71  64  22  91  69  58  88  72
 
Use the partitioning algorithm presented in class (see quicksort handout).  Give the arguments passed to partition() on each call and the value returned.  Show the array after each call to partition(). 
bullet J.  Say partition() is applied to an array a of size n, with distinct elements.  Let us say that partition() produces a bad split if either the left or the right subarray has size less than n/4.  What is the probability of a bad split if we choose the pivot element as
    a)    a single random element from a?
    b)    the median of three distinct random elements of a?
    c)    the median of five distinct random elements of a?
    d)    the median of seven distinct random elements of a? 
bullet Exercise 9.3-1 
bullet Exercise 9.3-8
 
bullet Exercise Set #5 (due Wednesday, July 11)
bullet Exercise 15.2-1
bullet Exercise 15.4-1
bullet Exercise 14.4-2
bullet Exercise 15.4-5 
bullet Exercise 15-6
bullet Exercise 15-7
bullet Exercises K and L
 
bullet Exercise Set #6 (due Wednesday, July 18)
bullet Click here for exercises
 



   
 

bullet

Homework Solutions
bullet

Solutions to Exercise Set #1

bullet

Solutions to Exercise Set #2

bullet

Solutions to Exercise Set #3

bullet

Solutions to Exercise Set #4

bullet

Solutions to Exercise Set #5  (4 exercises)

bullet

Solutions to Exercise Set #6  (available Wednesday afternoon)
 

bullet

Exams (study guides, solutions)  
bullet

Solutions to Quiz #1

bullet

Final Exam Study Guide

bullet

Sample Problem on Evaluating Polynomials and The FFT

bullet

Handouts (require Adobe Acrobat Reader) 
bullet

Fast Exponentiation

bullet

Rate of growth of functions: An example

bullet

Rate of growth of functions

bullet

Rate of growth: Exponentials, polynomials, and logarithms

bullet

Factorials

bullet

Summation by parts

bullet

Examples of iterative and recursive algorithms

bullet

Merging and Mergesort

bullet

Recurrences:  Approximating floor(n/2) and ceiling(n/2) by n/2

bullet

Solving recurrences: Recurrence Trees

bullet

Solving recurrences: The Master Theorem

bullet

An Extension to The Master Theorem

bullet

Sorting algorithm: Taking advantage of order present

bullet

Sorting algorithms: Stability

bullet

Straight insertion sort

bullet

Nearly complete binary trees and heapsort (handed out in class on 06/18)

bullet

Example of heapsort

bullet

The heapsort algorithm

bullet A decision tree for straight insertion sort
bullet

A decision tree for mergesort

bullet

Quicksort

bullet

Quicksort (extra space)

bullet

Quicksort (performace)

bullet

Selection (finding the kth smallest) in linear expected time: Example

bullet

Selection (finding the kth smallest) in linear expected time:  The algorithm

bullet Order of Matrix Multiplication
bullet Longest Common Subsequence
bullet All-pairs Shortest Path Algorithm in Graphs
bullet

Minimal Spanning Trees

bullet

Prim's Algorithm and Dijkstra's Algorithm

bullet Graphs and Digraphs
bullet

Breadth-first Search

bullet

Depth-first Search: Examples

bullet

The Depth-first Search Algorithm

bullet

Applications of Depth-First Search

bullet

String Matching with Finite Automata

 

bullet

Useful links
bullet

MSCS Department home page

bullet

UIC home page