CPSC 327 Data Structures and Algorithms Spring 2009

# CPSC 327 Syllabus

AssignmentsImportant Dates

### Week 1: 1/19-1/23

Topics: introduction; algorithm analysis

Mon

Wed Reading: Edmonds ch 23.1, 24 (review if you aren't familiar with the mathematics of logs and exponents), 25 (introduction and section 25.1 only), 26 (introduction and section 26.1 only)

Thinking Problem: An algorithm takes n English words as input. Is the number of words a fair measure of input size? Explain.

homework #1
due Fri 1/23

Fri   homework #2
due Mon 1/26

### Week 2: 1/26-1/30

Topics: applying algorithm analysis, motivating applications (sorting and lookup)

Mon   homework #3
due Wed 1/28

Thinking Problems:

• How do you delete an element from a hashtable?
• How likely are collisions? Do a calculation: assuming that each day is equally likely as someone's birthday, what is the probability that there are no shared birthdays in a class of 30 students?

Notes:

homework #4
due Fri 1/30
project #1
due Wed 2/11

Fri   homework #5
due Mon 2/2

### Week 3: 2/2-2/6

Topics: iterative algorithms

Thinking Problem: Using example 1.4.1, write down code or pseudocode for an actual implementation of selection sort. Point out how the code matches up with the 11 steps given e.g. how is the measure of progress reflected in the code.

homework #6
due Wed 2/4

Thinking Problem: Section 2.2 talks about "bounded memory" - in other words, the algorithm is only allowed to use Θ(1) space. Step 4 of example 2.2.1 states that this requirement means we cannot simply count the number of 0s and 1s in the input. (a) Write down an expression for n, the input size, in terms of bits. (b) Write down an (exact) expression S(n) for the space needed to store counts of the number of 0s and the number of 1s in the input. (c) What is the big-Theta for your S(n)?

homework #7
due Fri 2/6

Fri Reading: Edmonds ch 4, 5

Thinking Problem: We came up with two ideas for the fractional knapsack problem: plan A takes the weight of items in the pack as the measure of progress and the loop invariant is that we have the best value for the current weight, and plan B takes the number of items considered as the measure of progress and the loop invariant is that we have the best value for items 1..i (those considered so far). For each of these two plans, identify the main steps, show that the loop invariant is established/maintained, and explain what the running time is. Do not assume that the items have first been sorted in any particular order.

Notes:

### Week 4: 2/9-2/13

Topics: recursion and recurrence relations

Mon Reading: Edmonds ch 8, 9 (skip the discussions of running times in ch 9)

Thinking Problem: Construct a recursive algorithm for the task of finding the smallest element in an array. (Yes, I know there is a simple iterative algorithm. That's not the point here.) Write your algorithm in code or pseudocode, and demonstrate that you satisfied the checklist for recursive algorithms in section 8.5.

Notes:

Thinking Problem: Do either #1 or #2 and any one of #3-#7 (two problems total) from exercise 27.1.1 (pages 400-401) - without looking at the solution in the back of the book.

Notes:

homework #8
due Fri 2/13

Fri Reading: Edmonds ch 9 (the discussions of running times this time)

Thinking Problem: In general, having fewer subproblems and reducing the amount of work needed to create and combine subproblems will make a recursive algorithm run faster. But what about specific advice? Imagine that you've developed a recursive algorithm with a time T(n) = a T(n/b) + f(n). Would it be more productive to think about how to reduce the number of subproblems (as was done in the exponentiation, multiplication, and matrix multiplication examples) or how to reduce the work done splitting/combining? Does your answer depend on the particular equation for T(n)? If so, how?

Notes:

homework #9
due Mon 2/16

### Week 5: 2/16-2/20

Topics: divide-and-conquer algorithms

Mon Thinking Problem: Design an algorithm for finding both the smallest and largest numbers in an array of size n using only 3n/2 comparisons. Give your algorithm in code or pseudocode, and justify why only 3n/2 comparisons are needed.

Notes:

homework #10
due Wed 2/18

Wed Thinking Problem: Revisit the VSLI chip testing algorithm from section 4.3. Give a recursive algorithm for solving this problem. (Follow the steps in section 8.3.)

Notes:

midterm #1
due Mon 2/23 in class
(review information)

Fri class rescheduled for Tue 2/24 at 10am

### Week 6: 2/23-2/27

Topics: divide-and-conquer algorithms; ADTs and data structures

Mon Notes: homework #11
due Wed 2/25

Thinking Problem: Categorize the ADTs presented in the reading according to how elements are positioned and the primary kinds of methods the collection supports:

• how elements are positioned: algorithmically (the ADT determines how elements are arranged) or manually (the user of the ADT has control over how elements are arranged)
• what methods the collection supports: determine if an element is a member of the collection, after/before (methods based on ordering of elements), access elements with highest priority, access elements at any position, access elements only at ends (first/last)

Wed Notes:
homework #12
due Fri 2/27

Fri   homework #13
due Mon 3/2

### Week 7: 3/2-3/6

Topics: trees

Wed Thinking Problem: exercise 10.4.1 (page 149), without looking at the solutions in the back of the book

Notes:

Fri class rescheduled for Tue 3/10 at 10am   project #2
due Mon 3/30

### Week 8: 3/9-3/12

Topics: trees

Thinking Problems:

1. Insert the elements 50, 60, 70, 20, 10, 25, 40, 30, 28 into an initially empty AVL tree, drawing the tree after each step.
2. Insert the elements 5, 16, 22, 45, 2, 10, 18, 30, 50, 12, 1 into an initially empty 2-4 tree, drawing the tree after each step.

Notes:

homework #14
due Thu 3/12 5pm

Tue

Notes:

Wed

Notes:

Thu

### Week 9: 3/23-3/27

Topics: graphs and graph algorithms

Mon

Thinking Problems:

• exercise 14.1.1 (page 178)
• exercise 14.3.3 #4, #5 only (page 188)

Notes:

homework #15
due Fri 3/25

Fri Notes:

### Week 10: 3/30-4/3

Topics: graph algorithms; greedy algorithms

Mon Notes: homework #16
due Wed 4/1

Wed Reading: Edmonds ch 16.1, 16.2.3

Thinking Problem: exercise 16.1.1 (page 235) [justify your answer in the style of the proof in the chapter (a proof or a counterexample) - don't just state "yes" or "no"]

Notes:

midterm #2
due Mon 4/6 in class
(review information)

Notes:

### Week 11: 4/6-4/10

Topics: greedy algorithms; recursive backtracking and branch-and-bound

Mon Notes:
• making change (example of "staying ahead" loop invariant and proof)
homework #17
due Wed 4/8

Thinking Problem: exercise 17.5.1 (page 265), without looking at the solutions in the back of the book

Notes:

homework #18
due Fri 4/10

Fri Notes: homework #19
due Mon 4/13

### Week 12: 4/13-4/17

Topics: branch-and-bound; dynamic programming

Mon Notes: homework #20
due Wed 4/15

Thinking Problems:

1. Does a dynamic programming algorithm have to be iterative? Can you write it recursively instead without changing the big-Oh?

2. Where does the polynomial running time come from?

Notes:
homework #21
due Fri 4/17

Fri Reading: Edmonds ch 19.1-19.4 (do at least one section for Friday and the rest for next Monday)

Notes:

homework #22
due Mon 4/20

### Week 13: 4/20-4/24

Topics: dynamic programming; reductions

Mon Reading: the rest of Edmonds ch 19.1-19.4

Notes:

homework #23
due Wed 4/22
project #3
due Tue 5/5

Thinking Problem: exercise 19.8.1 (just explain how map the elephant problem to the graph problem, and how to turn a solution to the graph problem into a solution for the elephant problem - you do not need to repeat how to solve the graph problem)

Notes:

Fri Notes:

### Week 14: 4/27-5/1

Topics: NP-completeness

Mon Reading: Edmonds ch 20-20.1 (introductory material and section 20.1)

Thinking Problem: exercise 20.1.1 (choose three of the parts)

Notes:

homework #24
due Fri 5/1

Fri Notes:

### Week 15: 5/4-5/5

Topics: nifty data structures (splay trees and skip lists)

Mon Notes:

Tue

Wed

Thu

Fri

Sat

Sun

Mon