ECS30 Winter 2014
2014-01-22
Homework #3 due Wed 2014-01-29 at 23:50
Use the handin directory hw3 to submit your work
1) Write a program that takes as input a depth (in kilometers) inside the earth an
ECS 30
Practice Midterm Key
The questions in this document may have appeared in midterms in previous years when
this class was taught by different instructors.
1. UNIX commands
a. (10 points) You just
ECS30 Winter 2014
Midterm2 practice exam
Note: the questions below are only examples. The actual
type and number of questions in the exam may differ.
1) What is printed if the following C fragment is
ECS 30
Closed book, closed notes.
Practice Midterm #2 Key
1. (10 points) Given the following makefile, called makefile. After I edit one.h, when I type make, which files will be
changed by gcc?
whole.
ECS30 Winter 2014
Practice Final Exam
Note: these problems are representative of problems in the final. The topics and number of
problems may differ.
1) (Answer in box) What is printed if the followin
ECS 30
Practice Midterm #2
The questions in this document may have appeared in midterms in previous years when this class was taught by
different instructors.
1. (10 points) You are given the followin
ECS30 Winter 2014
2014-02-12
Homework #5 due Wed 2014-02-19 at 23:50
Use the handin directory hw5 to submit your work.
1) Write a program that orders three double numbers by increasing value. The prog
ECS30 Winter 2014
2014-01-06
Homework 1 due Mon 2014-09-13 at 23:50
Use the handin directory hw1 to submit your work
1) Get familiar with the web site http:/csifdocs.cs.ucdavis.edu
2) Log in to a CSIF
ECS30 Winter 2014
2014-01-31
Homework #4 due Mon 2011-02-10 at 23:50
Use the handin directory hw4 to submit your work
1) Write a program that prints the multiplication table for numbers 1 to 9. The pr
ECS30 Winter 2014
2014-02-21
Homework #6 due Wed 2014-03-05 at 23:50
Use the handin directory hw6 to submit your work.
1) Write a program that computes an approximation of the integral
for the functio
ECS30 Winter 2014
2014-03-05
Homework #7 due Fri 2014-03-14 at 23:50
Use the handin directory hw7 to submit your work.
1) Write a program that prints the number of words found in a text file. Words ar
ECS30 Winter 2014
2014-01-13
Homework #2 due Wed 2014-01-22 at 23:50
Use the handin directory hw2 to submit your work
1) Write a program to compute the mileage reimbursement for a salesperson at a rat
ECS122A Lecture Notes on
Algorithm Design and Analysis
Winter 2018
http:/www.cs.ucdavis.edu/bai/ECS122A
Professor Zhaojun Bai
1 / 12
Overview
I. Introduction and getting started
II. Growth of function
II. Growth of Functions and
Asymptotic Notations
1 / 13
Overview
I
Study a way to describe the growth of functions in the limit
asymptotic efficiency
I
Focus on whats important (leading factor) by ab
IV. Divide-and-Conquer Algorithms
1/9
Divide-and-Conquer algorithms Overview
The divide-and-conquer (DC) strategy solves a problem by
I
Breaking the problem into subproblems that are themselves smalle
III. Divide-and-Conquer Recurrences
and the Master Theorem
1/8
Divide-and-Conquer recurrences
I
Divide-and-Conquer (DC) recurrence
n
+ f (n)
T (n) = a T
b
where
I
I
constants a 1 and b > 1,
function f
Handout
Recurrence Relations Review
1. A recurrence relation for the sequence cfw_an is an equation that expresses an in terms of one
or more of the previous terms of the sequence, namely, a0 , a1 ,
Huffman codes
I
used for data compression, typically saving 20%90%
I
Basic idea:
represent often encountered characters by shorter (binary) codes
1 / 10
Huffman codes
Example
I
Suppose we have the fol
V. Greedy Algorithms
1 / 10
Greedy algorithms Overview
I
Algorithms for solving (optimization) problems typically go through a
sequence of steps, with a set of choices at each step.
I
A greedy algorit
VI. Dynamic Programming
1 / 10
Dynamic Programming Overview
I
Not a specific algorithm, but a technique (like Divide-and-Conquer and
Greedy algorithms)
I
Developed back in the day (1950s) when program
Matrix-matrix multiplication
I
Problem:
Given n n matrices A and B, compute the product
C = A B.
I
Traditional method: (i, j, k)-triple-loop
for i = 1 to n
for j = 1 to n
C(i,j) = 0
for k = 1:n
C(i,j)
0-1 knapsack problem
Problem statement:
I
Given n items cfw_1, 2, . . . , n
I
Item i is worth vi , and weight wi
I
Find a most valuable subset of items with total weight W
Rule: have to either take an
The closest pair point
Problem statement:
Given a set of n points on a line (1-dimensional, unsorted), find
two points whose distance is smallest.
Remark:
I
The problem is known as the closest pair pr
Dept. of Computer Science, University of California, Davis
ECS120, Fall 2017
Instructor: Rob Gysel
Midterm
October 27th , 2017
Name:
Student ID:
Do not open the exam until instructed to do so.
You m
ECS122A Problem Set #4
Solution
1. Solution: An acceptable solution is to use the Greedy-Activitiy-Selection algorithm
we learned in the class:
We first find a maximum-size set S1 of compatible activ
3.
4.
5.
Th
6.
sh is
ar stu
ed d
vi y re
aC s
o
ou urc
rs e
eH w
er as
o.
co
m
1.
2.
ECS 50 Midterm Review Guide
Know what all of the instructions on the Intel Cheat Sheet do and how to use them.
Unde
Midterm I Solution
1. (a) (1.5pts) Answer.
O(g(n) = cfw_f (n) : c, n0
0 f (n) cg(n)
such that
for n n0
(b) (1.5pts) Solution: Need to find constants c and n0 such that (n + 3)2 cn2 for all n n0 .
For
ECS122A Problem Set #2 Solution
1. (a) We need to find constants c1 , c2 , n0 > 0 such that
0 c1 n3 (n + 3)3 c2 n3
for all n n0 .
Note that
1
n n + 3 2n
2
When all parts are raised to the power 3.
whe
ECS122A Problem Set #5
Due: 4:00pm, February 21, 2018
1. Consider a modification of the rod-cutting problem in which, in addition to a price pi for each
rod, each cut incurs a fixed cost of c. The rev