Homework #2
due Wed 1/29
For each problem, develop an iterative algorithm to solve the problem using the 15-step process.
Write down each of the steps. (You can skip the implementation details and running time.) Also
identify which approach you are using
Questions
Observations
Once an algorithm has been found,
is it correct?
how much time does it take?
can we do better?
Section 0.2 raises two key points.
some functions grow much more quickly that others
exponential algorithms can take impractically l
HW 2
2. basic steps
HW 2
- keep it basic!
Establishing the loop invariant often requires proper
initialization be sure to state what that initialization is!
strategy: compare element to maxsofar
basic step: compare two numbers
e.g. maxsofar is the maxim
Iterative Algorithms.
Developing an Iterative Algorithm
.do repetition using loops.
Two main concerns:
figuring out what the repeated step is
convincingly arguing correctness
.solve problems by moving towards the solution one
iteration at a time.
Our st
HW 2
HW 4
Program captioning: assign employees to programs so that
no employees are assigned overlapping programs and the
fewest number of employees are used.
f(n) = (log n)(log n), g(n) = n/log(n)
Tips/tricks/strategies:
more of the input
simplify alg
HW 7
Developing Recursive Algorithms
Is the number of English words a fair measure of input
size?
establishing the problem
1. specifications
2. size
sums
brainstorming ideas
3. basic steps
i from 0 to n: 7 i3 300 i2 + 16
i from 1 to log n: n i 2
i fr
Patterns
Example
Graph coloring problem d+1 colors, at most d neighbors
Algorithms utilizing a particular approach (e.g. more of the
input) often have similar forms for some of the steps.
input elements
nodes
3. measure of progress
the number of nodes c
HW 5
Dealing With Sums
The asymptotically faster algorithm takes longer when the
program is run. Why?
Sums arise in algorithm analysis when the amount of work
done increases or decreases with each loop iteration.
small n
(and) constant factors, differen
Example
Example
A sorted matrix is a 2D array of numbers such that the
numbers increase across each row and down each column.
(Assume all of the numbers are distinct no duplicates.)
Monster problem.
most obvious measure of progress
distance to shore
Loc
Homework #4
due Mon 2/3
1. Exercise 0.1, pages 8-9. Do parts (a)-(p). (Part (q) is optional.) Justify each of your
answers using the definitions of O, , and , and show your work. If you aren't familiar
with the functions, try plotting them (just be carefu
Homework #3
due Fri 1/31
For each problem, develop an iterative algorithm to solve the problem using the 15-step process.
Write down each of the steps. (You can skip the implementation details and running time.) Also
identify which approach you are using
Homework #5
due Wed 2/5
1. Alice and Bob each implement different algorithms for solving a particular problem.
When they run their programs, they find that the one with the asymptotically faster
algorithm takes longer. What could be going on?
Homework #1
due Mon 1/27
Choose ONE of the following problems.
For your chosen problem, develop an iterative algorithm to solve the problem using the 15-step
process. Write down each of the steps. If you try several approaches or consider multiple
possibi
HW 3
Possible invariants:
left * right + result = x * y
result = product of y and the
number represented by the
rightmost k bits of the
binary representation of x
Stating these in combination
with the exit condition yields
the correct answer.
left * ri