CMPS 101
Homework Assignment 3
Solutions
1. Exercise 1 from the induction handout.
n(n 1)
Prove that for all n 1 : i
. Do this twice:
2
i 1
a. Using form IIa of the induction step.
b. Using form IIb of the induction step.
2
n
3
n(n 1)
Proof: Let P
CMPS 101
Homework Assignment 5
Solutions
1. Let G be a graph on n vertices, let A be its adjacency matrix (as described in the Graph Theory
handout), and let d 0 be an integer. Show that the ij th entry in Ad is the number of walks in G of
length d from v
CMPS 101
Homework Assignment 5
Solutions
1. (This is the 2nd exercise on page 1 of the handout on recurrence relations.) Define the function () by
the recurrence
0
S ( n)
S ( n / 2 ) 1
n 1
n2
Use the iteration method to show that S (n) lg(n) , and hence
CMPS 101
Homework Assignment
1. Show that any connected graph G satisfies |()| |()| 1. Hint: use induction on the number
of edges.
2. Let G be a graph on n vertices, A its adjacency matrix (as described in the Graph Theory handout), and
let d 0 be an inte
CMPS 101
Homework Assignment 3
1. Let f (n) be a positive, increasing function that satisfies f (n / 2) ( f (n) . Show that
n
f (i) (nf (n)
i 1
(Hint: follow the Example on page 4 of the handout on asymptotic growth rates in which it is proved
n
that
i
k
FinalReview(FULLSOLUTIONSAVAILABLENOW)
1. Question1
https:/classes.soe.ucsc.edu/cmps101/Summer15/Handouts/Graphs.pdf
a. Lemma1
b. Lemma2
c. Lemma3
d. Lemma4
2. DFS(G)True/False
a. w,gtree
F
b. b,wback
F
c. g,bforward
T
d. b,gcross
F
e. g,gtree
T
f. b,bfor
CMPS 101
Summer 2015
Midterm Exam 2
Solutions
1. (20 Points) Use the Master Theorem to find tight asymptotic bounds for the following recurrences.
a. (10 Points) T (n) 10T (n / 3) n2
Solution:
Let log 3 10 2 . Then 0 since 9 10 2 log3 9 log3 10 . Therefor
CMPS 101
Algorithms and Abstract Data Types
Summer 2015
Midterm Exam 1
Solutions
1. (20 Points) Determine whether the following statements are true or false. Prove or disprove each
statement accordingly.
a. (10 Points) If h1 (n) ( f (n) and h2 (n) ( g (n)
CMPS 101
Homework Assignment 4
Solutions
1. Consider the function T (n) defined by the recurrence formula
1 n 3
6
T ( n)
n3
2T ( n / 3 ) n
a. Use the iteration method to write a summation formula for T (n) .
Solution:
T (n) n 2T ( n / 3 )
n 2( n / 3 2T
CMPS 101
Homework Assignment 2
Solutions
1. p.50: 3.1-1
Let f (n) and g (n) be asymptotically non-negative functions. Using the basic definition of notation, prove that f (n) g (n) (max( f (n), g (n) .
Proof:
Since f (n) and g (n) are asymptotically non-n
CMPS 101
Homework Assignment 1
Solutions
1. p.27: 2.2-2
Consider sorting n numbers stored in array A by first finding the smallest element of A and
exchanging it with the element in A[1] . Then find the second smallest element of A and exchange it
with A[
CMPS 101
Homework Assignment 8
Solutions
1. B.5-4 page 1180
Use induction to show that a nonempty binary tree with n nodes and height h satisfies h lg n .
Hint: use the following recursive definition of height discussed in class:
h(T ) 0
1 max( h( L),
CMPS 101
Homework Assignment 5
Solutions
1. (This is the 2nd exercise on page 1 of the handout on recurrence relations.) Define the function () by
the recurrence
0
S ( n)
S ( n / 2 ) 1
n 1
n2
Use the iteration method to show that S (n) lg( n) , and henc
CMPS 101
Homework Assignment 6
Solutions
1. Show that any connected graph G satisfies |()| |()| 1. Hint: use induction on the number
of edges.
Proof:
Let = |()| and = |()|. We proceed by induction on m.
I. Let m 0 . Then being connected, G can have only o
CMPS 101
Final Review Problems
Be sure to look at the problems on all previous review sheets and homework assignments. Bear in mind that
some of material for the later problems has not yet been covered, and may not be by the last day of class. If
that is
CMPS 101
Algorithms and Abstract Data Types
Fall 2016
Description: Studies basic algorithms and their relationships to common abstract data types. Covers the
notions of abstract data types and the distinction between an abstract data type and an implement
CMPS 101
Homework Assignment 3
1. Let f (n) be a positive, increasing function that satisfies f (n / 2) ( f (n) . Show that
n
f (i) (nf (n)
i 1
(Hint: follow the Example on page 4 of the handout on asymptotic growth rates in which it is proved
n
that
i
k
CMPS 101
Algorithms and Abstract Data Types
Programming Assignment 3
In this assignment you will create a calculator for performing matrix operations that exploits the (expected)
sparseness of its matrix operands. An n n square matrix is said to be sparse