CS 141
Unweighted Graphs
Problem (un-weighted graphs)
Stefano Lonardi, UCR
1
CS 141
Weighted graphs
Problem (analysis of Dijkstra)
Stefano Lonardi, UCR
2
CS 141
Problem (Dijkstras vs BFs)
Problem (MST)
Let G=(V,E) be a weighted undirected
graph and let C
CS 141, Fall 2014
Homework 2
Problem 1. (25 points)
Given the following recurrence relation
T (n) =
1
4T
n=1
n
+3 n>1
2
1. Solve it exactly (i.e., without using any asymptotic notation) by iterative substitutions
2. Prove by induction that your exact so
CS 14 - Summer 2004 - Midterm
August 26, 2004
1
Multiple Choice
Fill in the bubble of the single-best answer for each question.
Do NOT make any unrequested marks on your answer sheet. You may use pen or pencil, but if
you want to change an answer, you MUS
CS 141, Fall 2014
Quiz 1/A
Problem 1. (9 points, 1 point each [upper bounds])
Mark by true or false each of the following (no need to prove)
4n2 log n +
4n2 log n +
4n2 log n +
4n2 log n +
4n2 log n +
4n2 log n +
4n2 log n +
4n2 log n +
4n2 log n +
n O(n2
CS 141, Spring 2014
Quiz 1/B
Problem 1. (20 points [analysis of iterative pseudocode])
Give a tight bound (using the big-theta notation) on the number of His produced by the
following method as a function of n. For simplicity, you can assume n to be a pow
CS 141 Homework 1
Due: April 10, 2015 @ 11:59pm
A
As per the course syllabus, homeworks should be prepared in L TEX, or some other
word-processing system that can handle equations; gures may be hand-drawn so long
as they are legible. Homework should be su
CS 141, Spring 2014
Homework 5
Problem 1. (25 points)
You are given a set T = cfw_(s1 , f1 ), . . . , (sn , fn ) of n tasks, where each task i is dened by the
start time si and a nish time fi . Each task has to be performed on one machine, and each machin
CS 141, Spring 2014
Homework 1
Problem 1. (10 points) Go to the Piazza discussion board (https:/piazza.com/class/
htabkbspmuv26f or follow the link from the class CS 141 webpage), register yourself, then select
hw1 from the left upper-corner and post one
CS 141 Homework 2
Greedy Algorithms
Due: May 8, 2015 @ 11:59pm
Problem 1
You are consulting for a trucking company that does a large amount of business shipping
packages between New York and Boston. The volume is high enough that they have to
send a numbe
CS 141 Homework 3
Dynamic Programming
Due: May 15, 2015 @ 11:59pm
Problem 1
Suppose youre running a lightweight consulting businessjust you, two associates, and
some rented equipment. Your clients are distributed between the East Coast and the
West Coast,
CS 141, Spring 2014
Homework 3
Problem 1. (25 points)
The median of a set of numbers cfw_a1 , a2 , . . . , an is the element ai such that there are n/2
elements smaller than or equal to ai , and there are n/2 greater than or equal to ai . In other
words,
CS 141, Fall 2014
Homework 1
Problem 1. (10 points) Go to the Piazza discussion board (https:/piazza.com/ucr/fall2014/
cs141/home or follow the link from the class CS 141 webpage), register yourself, then select hw1
from the left upper-corner and post one
CS 141
Greedy
Greedy (greedy-choice proof)
Stefano Lonardi, UCR
1
Problem 24. (points)
We are given a set T = cfw_(s1 , f1 ), . . . , (sn , fn ) of n lectures that need to scheduled among a very large
number of lecture halls. A lecture i is dened by its s
CS 14: Introduction to
Data Structures & Algorithms
First Name:
May 1, 2003
Midterm, Form: A
ID Number:
Last Name:
Signature:
This test contains two sections, a MULTIPLE-CHOICE section and a SHORT-ANSWER
section. Please make sure to pace yourself properly
Name:_
SSN:_
Login: _
CS 14 - Spring 2002
Midterm
Be sure to read each problem carefully and follow the directions. Please feel free to ask if you have any
questions. Please work wisely. Do not spend too much time on any one problem.
Problem 1 - 24
24
Pro
CS 14: Data Structures and Algorithms
Friday, October 31, 2003
Midterm Exam, Form: A
This exam is worth 60 points and lasts 40 minutes. There are 30 multiple choice
questions, which means you should not spend more than 1 minute and 20 seconds
per question
Write some problems that you would like me
to cover on Thursday
Asymptotic Notation
Asymptotic Notation
Special classes of algorithms
constant:
logarithmic:
linear:
quadratic:
cubic:
polynomial:
exponential:
Factorial:
O(1)
O(log n)
O(n)
O(n2)
O
I certify that this submission represents my own original work
x_
Date:_
Problem 2 Solution:
1 The inner summation represents the inner while loop and the outer
nlogn
n
i=1
j=1
summation represents the outer for loop.
Evaluating the inner summation yield
CS141 Homework 2
due Thursday, October 22
Solution 1: We start by comparing elements a[ k/2 ] and b[ k/2 ]. Two cases are possible: either a[ k/2 ] >
b[ k/2 ], or a[ k/2 ] < b[ k/2 ]
Case 1: Suppose a[ k/2 ] > b[ k/2 ]. What does this tell us about where
CS141 Homework 1
due Thursday, October 15
Solution 1:
1 8n
C1 = cfw_ ,
+ 20, 20
n n!
C2 = cfw_lg lg n
C3 = cfw_lg2 n
n
C4 = cfw_
lg n
C5 = cfw_lg (n!)
C6 = cfw_(n + 16)(8n0.5 + lg n)
n2 8n2
,
+ n lg n
ln2 n lg2 n
C8 = cfw_7n2 30n + 2
C7 = cfw_
C9 = cfw_(
CS 141 Homework 3
Dynamic Programming
Due: May 15, 2015 @ 11:59pm
Problem 1
Suppose youre running a lightweight consulting businessjust you, two associates, and
some rented equipment. Your clients are distributed between the East Coast and the
West Coast,
CS 141 Homework 2
Greedy Algorithms
Due: May 8, 2015 @ 11:59pm
Problem 1
You are consulting for a trucking company that does a large amount of business shipping
packages between New York and Boston. The volume is high enough that they have to
send a numbe
CS 141
Analysis
Analysis
Mark T/F (no need to prove/explain)
Stefano Lonardi, UCR
1
CS 141
Analysis
Mark T/F (no need to prove/explain)
Analysis (recurrence relation)
Problem: Solve using the Master Theorem
1
T (n ) = n 2
7T 2 + n
n =1
n >1
Solution:
x_
Date:_
Problem 1 Solution:
If v is a 2k x 1 column vector with i > 0, then we have:
with
v 1 and v 2
We can compute
being
H k v
k 1
2
x 1 column vectors. Thus the multiplication of
using two multiplications
H k1 v 1
and
H k v
is:
H k1 v 2 , dividing th
x_
Date:_
Problem 1 Solution:
We have k sorted arrays, with n elements, and we want to combine them into a single sorted
array of kn elements. Here we can apply a divide-and-conquer algorithm very similar to
mergesort. To sort k arrays of n elements each
2/22/16
Weighted Graphs
1
Final Exam
Saturday, December 5
Quiz 3
Thursday, Nov. 19
2
Discussion
Wednesday, Nov. 25, 5 6 pm
extra office hour for all students
3
Quiz 1 grade !
If
(Q2 + Q3)/2 > Q1
you can request a score replacement
(in writing)
by December
Write some problems that you would like me
to cover on Thursday
Asymptotic Notation
Asymptotic Notation
Special classes of algorithms
constant:O(1)
logarithmic: O(log n)
linear:
O(n)
quadratic: O(n2)
cubic: O(n3)
polynomial: O(nk), k 1
exponentia
Midterm Exam CS 170
Last Name:_
First Name:_
Student ID:_
Note: Please write carefully, if necessary PRINT.
Do not touch this exam until you are told to do so!
This exam will be collected along with your scantron. If
you need to do calculations, do them o
CS 141 Homework 1
Due: October 7, 2016 @ 11:59pm
As per the course syllabus, homeworks should be prepared in LATEX, or some other
word-processing system that can handle equations; figures may be hand-drawn so long
as they are legible. Homework should be s
CS 141 Homework 1
Yadan Luo
October 5, 2016 @ 11:59pm
Problem 1
The following code fragment implements Horners rule for evaluating a polynomial
P (x) =
n
X
ak x k
k=0
= a0 + x(a1 + x(a2 + . . . + x(an1 + xan ) . . .),
given the coefficients a0 , a1 , . .
CS 141 Homework 2
Greedy Algorithms
Due: November 4, 2016 @ 11:59pm
Problem 1
You are consulting for a trucking company that does a large amount of business shipping
packages between New York and Boston. The volume is high enough that they have to
send a
10/14/16
Greedy
1
Huffman codes
2
Optimization problem
Given a character c in the alphabet
let f(c) be the frequency of c in the file
let dT(c) be the depth of c in the tree = the
length of the codeword
We want to minimize the number of bits
required