ECS 122A: Algorithm Design and Analysis Handout M
JC Davis 7 Charles Martel May 27 2008
Sample Midterm Exam
1 Short answers [40 points]
0 (10) Part A. Solve the following recurrence by nding a (90 bound for Assume
that T(n) is 1 for n S 1, and other

CS 122A Fall 2015, Quiz 2
Mark your answers on your scantron sheet using a pencil.
Be sure to also mark in your student ID number, and be sure to write you section
number on your scantron.
Closed Book. You have 10 minutes.
1. Which of the following are no

Some problems from previous nals in CS 122A.
These are NOT a comprehensive coverage of the class the way it was
taught in F2015. But each of these questions relates to material that was
covered. Refer to my earlier post on the book chapters covered, to se

CS 122A Fall 2015, Quiz 2
Mark your answers on your scantron sheet using a pencil.
Be sure to also mark in your student ID number, and be sure to write you section number on
your scantron.
Closed Book. You have 10 minutes.
1. Which of the following things

CS 122A Fall 2015, Quiz 2
Mark your answers on your scantron sheet using a pencil.
Be sure to also mark in your student ID number, and be sure to write
you section number on your scantron.
Closed Book. You have 10 minutes.
1. How quickly can all of the st

CS 122A Fall 2015, Quiz 1
Mark your answers on your scantron sheet using a pencil.
Be sure to also mark in your student ID number, and be sure to write
you section number on your scantron.
Closed Book. You have 10 minutes.
1. Use the Master method to solv

CS122A,Fall2015Homework8&9Solutions
HW8
2. A(i, j) denote the minimum cost of the triangulation for the polygon spanned by
Let
vertices i, i+1, , j. Consider thetriangleincludingedge(i,j),ifwedenotethethirdvertexof
itask(i<k<j),thenwegetthis:
A(i,j)=min(

1. Do problem 6.9 in the book.
To be clear about the problem, the string has length n, and input to the
problem consists of m < n points where the string will be cut. So we know
the m + 1 substrings will result from these cuts. The only problem is how to

CS 122A Fall 2015 Final Exam. Closed book, no calculators. Start
answers to each problem set (1 through 7) on a new page. Try to be concise.
No need to reprove things that were proven in class.
1. In a list of n distinct numbers L, an inverted pair is a p

This is another explanation for the solution to problem 1 on HW 9. This
is closer to the way it was discussed today in the review session.
The base cases for the DP specify the values of C(v) and C(v, x), for
every leaf v of T , and every character x in t

ECS122A Homework Assignment #2
Due: 4:00pm, January 22, 2016
1. (a) Prove that (n + 3)3 = (n3 )
(b) Prove that for any real constants a and b, where b > 0,
(n + a)b = (nb )
Note: to establish the relationship f (n) = (g(n), we need to nd the proper consta

ECS122A Midterm I Review Checklist
Here are a list of math, concepts and denitions, algorithms that you should know from lecture,
discussion and homework. This is not meant to be comprehensive. It is merely a reminder of what we
need to review for the upc

Greedy algorithms
Overview:
Algorithms for solving (optimization) problems typically go through a
sequence of steps, with a set of choices at each step.
A greedy algorithm always makes the choice that looks best at the
moment, without regard for future co

Finding the closest pair of points in 1-dimension
Problem statement:1
Given a set S of n points on a line (unsorted), nd two points
whose distance is smallest.
Bruce-force:
Pick two of n points and compute the distance
Cost: (n2 )
1 Section
33.4 of [CLRS,

ECS122A
Warmup Exercises (no need to hand in)
1. Let T (n) be dened by the following recurrence relation
T (0) = T (1) = 1
T (n) = T (n 1) + T (n 2) + 1 for
n2
Show that
T (n) = 2Fn 1
for
n 0,
where Fn is the nth Fibonacci number, i.e.,
F0 = F1 = 1;
Fn =

Growth of Functions and Asymptotic Notations
Growth of Functions and Asymptotic Notations
Overview:
Study a way to describe behavior of functions in the limit .
asymptotic eciency
Describe growth of functions
Focus on whats important by abstracting lower-

Matrix-matrix multiplication
Problem:
Given n n matrices A and B, compute the product C = AB.
Traditional method: triple-loop
Complexity: T (n) = (n3 )
Divide-and-conquer
1. Naive implementation partition and then direct block multiplication
C=
C11
C21
C1

Introduction and Getting Started
Introduction
Algorithm is a tool for solving a well-specied computational problem
Algorithms as a technology
Basic questions about an algorithm
1.
2.
3.
4.
5.
Does it halt?
Is it correct?
Is it fast?
How much memory does i

Divide and Conquer Algorithms
The Maximum-subarray Problem
Problem:
Input: an array A[1.n] of (positive/negative) numbers.
Output: Indices i and j such that A[i.j] has the greatest sum of
any nonempty, contiguous subarray of A, along with the sum of
the v

Divide-and-Conquer recurrences
and Master Theorem
Divide-and-Conquer recurrences
Divide-and-Conquer (DC) recurrence
T (n) = a T
n
+ f (n)
b
where constants a 1 and b > 1, function f (n) is nonnegative.
Example: the cost function of Merge Sort
T (n) = 2 T

ECS122A Homework Assignment #5
Due: 4:00pm, May 11, 2015
1. Consider a modication of the rod-cutting problem in which, in addition to a price pi for each
rod, each cut incurs a xed cost of c. The revenue associated with a solution is now the sum of
prices

Notes on nding Strong Components in a Directed
Graph.
Dan Guseld, Jan. 31, 2013.
I dont like the way the book describes the algorithm to nd strong components in a directed graph. So here I am going to rewrite the algorithm
(given on page 104, 8 lines from

CS 122a Fall 2010, HW 1 Due Friday October 1
Read the text through the proof of 1.6, ending on page 9. Then do
problems 1,2 and 4 starting on page 22. Do not use the internet or other
books to look for solutions to these problems. Just use the material in

308 122A: Algorithm Design and Analysis Handout Z
JC Davis 7 Charles Martel June 37 2008
Sample Final
1 Algorithm Usage [60 points]
1.1. (5 points) ) You are given a computer network where some pairs of computers (but not all) are
connected by a 2wa

ECS122A Midterm I Review Checklist
Here is a list of math, concepts and definitions, algorithms that you should know from lecture,
discussion and homework assignments #1, #2 and #3. This is not meant to be comprehensive. It is
merely a reminder of what we

ECS122A Homework Assignment #7
Due: 4:00pm, March 10, 2017
1. Let G = (V, E) be a connected undirected graph with distinct edge weights. Prove that G has a
unique minimum spanning tree.
2. Run Prims algorithm with the root vertex a for finding the minimum

D EPT.
OF
C OMPUTER S CIENCE , U NIVERSITY OF C ALIFORNIA , D AVIS
ECS122A Syllabus*
Design and Analysis of Algorithms
Lecture: MWF 9:00-9:50am, 180 MedSci C
Instructor: Dr. Rob Gysel, rsgysel at ucdavis dot edu
Office: 1037 Academic Surge (south of MSB)