CPSC 450 Spring 2008

CPSC 450 Syllabus

 ReadingAssignments

Week 1: 1/21-1/25

Topics: algorithm analysis

Tue    
Thu GT ch 1 (only read "Accounting Method" in 1.5.1) R-1.10 - R-1.14 (five exercises), page 48
Give a reasonably tight bound e.g. saying that something with a running time of 3n+5 is O(n3) is true, but O(n) is the tight bound. You do not need to prove your big-Oh characterization using the definition in section 1.2.1 (i.e. finding values for c and n0), but you should provide some explanation/justification for your answers by either coming up with an expression for the number of steps and then giving the big-Oh characterization of that expression or by using an argument similar to the examples in sections 1.4.1 and 1.4.2.

Order the following list of functions by the big-Oh notation, from slowest-growing to fastest. Group together those functions that are big-Theta of one another.

6n(log n) 2100 log log n log2 n 2log n
n0.01 4n3/2 5n n(log4 n) 2n

Justify your ordering by stating values of c and n0 which satisfy the definition of big-Oh for each consecutive pair of functions in your ordering. (i.e. if you claim that f(n) grows more slowly than g(n), which grows more slowly than h(n), you need to demonstrate the f(n) = O(g(n)) and that g(n) = O(h(n))) Keep in mind that to demonstrate big-Theta, you need to show both f(n) = O(g(n)) and g(n) = O(f(n)).


GT C-1.21, page 52.
Hint: think about what constraints O(n)-time puts on the number of times you can examine elements in the array, and what constraints O(1)-space puts on the variables you can have.

Week 2: 1/28-2/1

Topics: the running times of common ADT operations; searching and lookup: hashtables, binary search trees, balanced binary search trees

Tue GT 2.1-2.2, 3.1.1, 2.5 For all of the exercises, justify your big-Oh times. (You don't need to get as detailed as counting statements or primitive operations, but provide some justification for why your answer is what it is.)

What is the big-Oh running time of the classic binary search algorithm (algorithm 3.1, page 143) when applied to a linked list instead of an array? Carry out the algorithm as described, so that key(mid) and elem(mid) involve counting from the beginning of the list in order to locate the key (or element) with the specified key.


Consider an alternative implementation of binary search, written in terms of the Sequence ADT. The idea is to keep track of the number of elements in the range so that the midpoint can be computed, but to then scan from the current location to the midpoint instead of starting at the beginning each time. What is the running time of this algorithm, if the Sequence is implemented using a doubly-linked list?

algorithm binarySearch ( S, k ) :
  input:  sequence S storing n items; search key k
  output:  position containing key k, or null if no such position

  /* initialize current location and range information */
  size = S.size()           /* number of elements in current range */
  current = S.first()       /* marks one end of current range */
  forward = true            /* if true, current is at beginning of range;
                               if false, current is at end */

  while size >= 1 do
    /* find middle of range */
    for count <- 1 to size/2
      if forward then
        current <- S.after(current)
      else
        current <- S.before(current)

    /* update range */
    if current.key() > k then
      if S.isFirst(current) then
        return null   /* if k is before the first thing, it's not there */
      current = S.before(current)
      size = size/2
      forward = false
    else if current.key() < k then
      if S.isLast(current) then
        return null   /* if k is after the last thing, it's not there */
      current = S.after(current)
      size = (size-1)/2
      forward = true
    else 
      return current

  return null

Consider a third alternative implementation of binary search, which avoids having to keep track of the size of the current range. The idea is to find the middle element by simultaneously counting forward and backward from the ends of the range. What is the running time of this algorithm, if the Sequence is implemented using a doubly-linked list?

algorithm binarySearch ( S, k ) :
  input:  sequence S storing n items; search key k
  output:  position containing key k, or null if no such position

  /* initialize range */
  first <- S.first()
  last <- S.last()

  while first != last do
    /* find middle of range */
    middle1 <- first
    middle2 <- last
    while middle1 != middle2 and middle2 != S.after(middle1) do
      middle1 = S.after(middle1)
      middle2 = S.before(middle2)

    /* update range - either middle1 == middle2 (odd number of things) or 
       middle1 is immediately before middle2 (even number of things) */
    if middle1.key() > k then
      last = S.before(middle1)
    else if middle1.key() < k then
      first = S.after(middle1)
    else 
      return middle1

  return null
Thu GT 2.3, 3.1.2-3.1.6, 3.2, 3.3.1-3.3.2 R-2.20-R-2.22 (three exercises), C-2.9, C-2.20
The last two involve traversals and properties of binary trees - things that were in the reading, but not discussed in class.

Week 3: 2/4-2/8

Topics: balanced trees - AVL trees, 2-4 trees, splay trees

Tue GT 3.2, 3.3.1-3.3.2, 3.4 R-3.3, R-3.10, C-3.5, C-3.10, C-3.14
For C-3.10, just discuss how you could locate all the elements (e.g. print them out) in the specified time; don't worry about returning an iterator.
Thu GT 3.4, 3.5 R-3.16, C-3.20, C-3.22
Implement the Ordered Dictionary ADT using a splay tree, and with skip lists. Implement the following methods: size(), isEmpty(), findElement(k), insertItem(k,e), removeElement(k), closestKeyBefore(k), closestElemBefore(k), closestKeyAfter(k), closestElemAfter(k), findInRange(k1,k2). findInRange(k1,k2) should return a vector containing all of the elements with key k such that k1 ≤ k ≤ k2. Keys k1 and k2 need not actually be in the dictionary. Your implementations should achieve the running times specified in the book for each operation (i.e. O(1) for size() and isEmpty(), O(log n) amortized/expected for findElement, insertItem, removeElement) or the best possible if not explicitly stated in the book. You may assume that both keys and elements are integers.
provided code: binarytree.h, binarytree.cc, dictionary.h, dictionary.cc

Week 4: 2/11-2/15

Topics: skip lists; priority queues and heaps

Tue GT 3.5, 2.4 C-3.28, C-3.29, R-2.18, C-2.32
For C-3.28, don't worry about locators, just describe how to carry out finding the closest key and closest element before a particular key in a skip list (and the running time of the operations).
Thu    

Week 5: 2/18-2/22

Topics: sorting, recurrence relations, selection; greedy algorithms

Tue GT 4.1, 4.3, 5.2.1, 4.4-4.6 R-4.14, C-4.9, C-4.10 (can you do better than O(n log n)?), C-4.14, C-4.25, R-5.4
An "in-place" method is one which uses only O(1) extra space, beyond the array containing the elements being sorted.
For R-5.4, solve the problems (at least until you get to a sum you can't resolve) using the expansion method.
Also: comparing big-Oh and experimental running times for sorting - run the program with
  ~bridgeman/cs450/sortdetective/run-sortdetective
(You should have permissions to do that - let me know if you have problems.)
Thu GT 5.1 C-4.24, C-4.26

Week 6: 2/25-2/29

Topics: greedy algorithms

midterm exam

Tue GT 5.1  
Thu GT 5.1 GT C-5.1, C-5.5

Week 7: 3/3-3/7

Topics: divide-and-conquer; the master method for solving recurrence relations

Tue GT 5.2  
Thu GT 5.2 GT C-5.6, C-5.7, C-5.8
For C-5.7, give the running time of your algorithm. For C-5.8, justify why the running time of your algorithm is O(n log n).

Week 8: 3/10-3/14

Topics: divide-and-conquer; dynamic programming

Tue GT 5.2  
Thu    

3/17-3/21

spring break


Week 9: 3/24-3/28

Topics: dynamic programming

Files for the splay tree / ordered dictionary project can be found in ~bridgeman/cs450/dictionary - the files include the abstract OrderedDictionary class and header and .o files for several implementations (2-4 tree, AVL tree, skip list, splay tree, sorted vector). In addition, there is a sample of how to get timing information - timer-example.cc uses the times system call to get the time before and after an operation (in the example, the operation is inserting the numbers 0-499 in that order) so the elapsed time can be computed. Finally, there's a tester tester.cc - it's something of an automated tester, as it performs a number of operations and calls a check method belonging to each structure to verify the structure's correctness after each operation. As it is often easier to check that the structure is valid than it is to ensure that the insertion/removal/etc is correct, this is a useful strategy for building one's confidence in the correctness of the structure (though it doesn't prove that the operations are implemented correctly).

Tue GT 5.3  
Thu GT 5.3 C-5.10, C-5.11, C-5.13
In all three cases, describe how to find the actual solution (the numbers in the subset B, the diagonals in the triangulation, the nodes in the independent set) in addition to whether or not B can be found, the weight of the triangulation, and the weight of the independent set. Also state and justify the running time of your algorithm.

Week 10: 3/31-4/4

Topics: dynamic programming

Tue GT 5.3  
Thu GT 6.1-6.3  

Week 11: 4/7-4/11

Topics: graphs: ADT, implementation, traversals

Tue GT 6.1-6.3 R-6.1, R-6.6, C-6.3, C-6.4, C-6.10, C-6.12
For C-6.12, any accesses to the graph should be written in terms of graph ADT operations. Also state and justify the running time of your algorithm.
Thu   R-6.8, R-6.9, R-6.11, C-6.13, C-6.18, C-6.19
For C-6.18, note that maximal is not the same thing as maximum.

Week 12: 4/14-4/18

Topics: graphs and graph algorithms

midterm exam, date TBD

Tue GT 6.4, 7.1  
Thu GT 7.1-7.3  

Week 13: 4/21-4/25

Topics: graphs and graph algorithms

Tue GT 7.1-7.3 R-7.1, R-7.2, R-7.3, R-7.4, R-7.7, R-7.10, C-7.2, C-7.3, C-7.7, C-7.8, C-7.9, C-7.10

Write a program to solve Problem A ("Low Cost Air Travel") from the 2006 World Finals of the ACM International Collegiate Programming Contest.

Your program should read input in the format specified, and produce output in the format specified. You should implement any data structures you need if there are not standard versions available (such as the STL vector and stack classes). Strive for an efficient solution - choose an algorithm, data structures, and implementations accordingly. (The appropriateness of your choices, as well as the correctness of your implementation, both count.)

Also hand in a description of your algorithm, and (as usual) justify its correctness and state/justify its running time.

Thu    

Week 14: 4/28-5/2

Topics: backtracking, branch-and-bound

Tue GT 13.5  
Thu   In the job assignment problem, there are n jobs, n employees, and an nxn matrix A where Aij is the cost of employee i performs job j. The task is to find a one-to-one assignment of jobs to employees with the lowest total cost. (One-to-one means that every job is assigned to one employee and every employee is assigned one job.)
Formulate a branch-and-bound solution for this problem: identify the key components of a branch-and-bound solution, and come up with the tightest lower/upper bound (whichever is appropriate) you can. Provide some justification for why your lower/upper bound is a lower/upper bound, and why it is reasonably tight.

Week 15: 5/5-5/6

Topics:

Tue    
Thu    

Reading Period and Exams: 5/7-5/13

final exam due Tue 5/13 9am


Valid HTML 4.01!