CIS 320
Homework Assignment 1
Due: September 21st
1. Compare the two functions - log2 n and
answer.
n and decide their asymptotic relationship. Prove your
2. For each of the following statements, either prove that the statement is true for all positive-va
CIS 320
Homework Assignment 2
Due: October 5 th
1. An inversion in an array A is a pair of indices i < j such that A[i] > A[j]. Show how you can modify
MergeSort to find the number of inversions in a given input array in O(n log n) time.
2. Consider the f
CIS 320
Homework Assignment 3
Due: October 26 th
1. Suppose we want to maintain a splay tree for a set of elements S. In addition to the usual operations
of insert, delete, and find, we want to support one other operation rank(x), which should return
the
Dynamic Programming
Conditions: 1.Optimal substructure 2. Overlapping subproblems(repeated subproblems solved
with memorization).
How to solve DP problem1. Parameterizing the problem(recurrence)
2. Base Case
Runtime: # of subproblems * time to solve each
Lecture 7 notes
'I. HAMHTONIAN PATH SATISFIAHHJTV
o HAMIIJTIONIAN PATH
Input
>:=: Graph G = 1: t'", E}
YeslflVe Question
>:=: Does there exist a Hamiltonian lath [a path that visits each node exactly
(nice) in G?
o SATISFIABILITY
Input
Set of
Lecture ll]I
Dynamic Programming
Shortest Taths, Chained hrlatrix \lultiplieaticm
All Pairs Shortest Path Problem
Tnput: Edge 1Weighted Graph G (VJ-7.; weight Funeti on we) on each edge
Task: Compute the length of the shortest path from every node i t
Midterm 1
Cheat Sheet
Logarithm/Exponent Rules
- 10gi(xy)= lost 36+ lost... .v
Note: The rule does not. apply to loga (x + y). A way to bound loge (x + y) would be to use
the following relationship:
logt (35+ y) 5 legs (21nax(x._ )0)
= loga 2 + logs I
FS & DFS runtime- O(V+E) Breadth employs a queue to ensure that all neighbors of node v are
looked at before neighbors of neighbors of v. Depth simply calls depth on each neighbor first.
DFS Edge types- Tree Edge-edges in depth first forest, Edge(u,v) is
Greedy Algorithms1. Cast the optimization problem as one where we make a choice and are left with a
subproblem
2. Prove there is an optimal solution to the original solution that makes a greedy choice, so
the greedy choice is always safe.
3. Demonstrate o
Relaxation- if the distance to v is greater than the distance to u + w(u,v) then update distance to
v through u.
Bellman-Ford algorithm to find single-source shortest paths in a graph w/ negative weights.
O(VE) runtime, relaxes each edge V-1 times, then c
CIS 320: Algorithms - Fall 2016
Proving lower bounds
For any computational problem there are many different (often infinitely many) algorithms that
solve the problem. To prove an upper bound of f (n) for the problem we need to show that there is
an algori