CSE 101, Winter 2012
Lecture 2 Notes
Class URL: http:/vlsicad.ucsd.edu/courses/cse101-w12/
Participation Exercise, January 12
Directions
Group yourselves into 2s or 3s
Write the cfw_names + 4th number of your SID for your group onto ONE
piece of paper

CSE 101, Winter 2012
Lecture 1 Notes
Class URL: http:/vlsicad.ucsd.edu/courses/cse101-w12/
Notes January 10 (1)
Moodle Quiz #1 ONLY allows re-tries before final submission.
In subsequent quizzes, your first submitted answer counts!
There are TWO discuss

Handout: Algorithms for graphs
DFS
CSE 101 Winter 12
DFS vs BFS
Idea. DFS starts at the root and explores as far They are both using basically the same idea:
as possible along each branch before backtracking.
Main loop:
v = EXTRACT-NEXT(X)
mark v as explo

THE HONG KONG UNIVERSITY OF SCIENCE & TECHNOLOGY
Department of Computer Science & Engineering
COMP 271: Design and Analysis of Algorithms
Fall 2010
Midterm Examination
Instructor: James Kwok (L1) / Huamin Qu (L2)
Date: Friday, 29 Oct. 2010
Time: 7:00pm 9:

1
Q1
For each subquestion, points are counted only when all relations are answered correctly. Points should not be
counted when answers are partially correct, i.e. missing or including extra relations.
(a) O, , (2 points)
(b) O, , (2 points)
(c) (2 points

COMP 271 Design and Analysis of Algorithms
Spring 2009 Midterm Exam
1. Multiple Choice (4 5 = 20 pts)
Each question below has exactly one of the following answers.
(a) (1)
(b) (log n)
(c) (n)
(d) (n log n)
(e) (n2 )
For each question, write down the lette

COMP 271 Design and Analysis of Algorithms
Spring 2009 Midterm Exam Solutions
1. Multiple Choice
1.1 (b) 1.2 (d) 1.3 (c) 1.4 (e) 1.5 (d)
2. (a) If n 3 we can solve the problem trivially. Let m = n/2 . We look at the two
elements A[m], A[m + 1]. There coul

CSE 101, Winter 2012
Lecture 3 Notes
Class URL: http:/vlsicad.ucsd.edu/courses/cse101-w12/
Notes January 17(1)
Comment on type-checking. Always make sure that you think
and say things that are relevant to the relevant mathematical
object.
E.g., You cant

CSE 101, Winter 2012
Lecture 4 Notes
Class URL: http:/vlsicad.ucsd.edu/courses/cse101-w12/
Participation Exercise, January 19
Directions
Group yourselves into 2s or 3s
Write cfw_name + last number of SID for each member of your group onto
ONE piece of

Why Algorithms? And What Should You Expect From This Course?
Andrew B. Kahng, [email protected] http:/vlsicad.ucsd.edu/~abk
Algorithms are the heart of computer science. They connect real-world needs and
applications to architectures, interconnection networks,

CSE 101 Winter 2012
Discussion Section Week 9 Notes
3/7/2012
Rudrata (Hamiltonian) s-t paths and cycles
Given an undirected graph G = (V, E ), a Rudrata s-t path begins at some node s in G and
visits each node in the graph exactly once before ending at t.

Model solutions
CSE 101, Winter 12
These "model solutions" are provided to give an idea of the level of detail and formality
that would receive full credit in homework writeups or exams.
1
Algorithm design
Exercise 3.11.
Design a linear-time algorithm whi

CSE101Winter2011
Practicemidtermquestions
Followingisasetofpracticemidtermquestionscollectedfromthemidtermsofpreviousyears.The
actualmidtermwillbefarshorter46questions.
Read all of the following information before starting the exam:
Show all work, clearl

CSE101Winter2011
Practicemidtermquestions
Followingisasetofpracticemidtermquestionscollectedfromthemidtermsofpreviousyears.The
actualmidtermwillbefarshorter46questions.
Read all of the following information before starting the exam:
Show all work, clearl

Example of a 4-problem, 60-point midterm
1. (15 points) DFS and strongly connected components (SCCs) in directed graphs
Consider the graph in Figure 1.
C
A
J
H
I
E
B
D
F
G
Figure 1
(a) (6 points) In what order are the SCCs found? Break any ties lexicograp

fi r y xf yh
qC1jhkxjvhr8#9jhuj
fi r i t
qc1xh#rdvyhH
p
m
tfi r i d rp y
8qCShqr1Hg`vhHuf
evt1tqvfjhht
t yxy
h ds t y xp fi r ws h i x h xs y t h xh y s x h
U`uHjhd8q9#c1d1U6cfw_`rHvf181rtjjkhvyvxr11vyAjHcfw_Hvfx
vtkxjH8ukscfqx1Hjd8ui18vfSvh1rtxvhrHvfd

CSE 101 Winter 12
Dynamic Programming examples
Section 6.2. Longest increasing subsequence (lots of details)
Problem. The input is a sequence of numbers a1 , . . . , an . A subsequence is any subset of
these numbers taken in order. An increasing subsequen

COMP 271 Design and Analysis of Algorithms
Fall 2009 Midterm Exam
1. Quick-Answer Questions (4 5 = 20 pts)
For each question below, write down the asymptotic (using ) result. You do not need to
justify your answers.
n
1.1 What is
i=1
i
2
3
?
1.2 What is t

COMP 271 Design and Analysis of Algorithms
Fall 2009 Midterm Exam Solutions
1. Quick Answer Questions
1.1 (1) 1.2 (n3 ) 1.3 (n) 1.4 (|E |) 1.5 (n).
2. We use divide-and-conquer:
FindLocalMinimal (Node u)
cfw_
if u is a leaf then
return u and stop;
else if

COMP 3711 Design and Analysis of Algorithms
Fall 2011
Homework 1
1. Give asymptotic upper bounds for T (n). Make your bounds as tight as possible. You may
assume that n is a power of 2.
(a)
T (1) = T (2) = 1
T (n) = T (n 2) + 1
if n > 2
(b)
T (1) = 1
T (n

COMP 271 Design and Analysis of Algorithms
2011 Spring Semester
Solutions of Homework 1
Problem 1
TA(n) =
TB(n) =
(n2)
()
Algorithm B is faster.
Case 2
(n3)
(2 )
Algorithm A is faster
Case 3
(logn)
(loglogn)
Algorithm B is faster
Case 4
(log3n)
( )
Algori

COMP 271 Design and Analysis of Algorithms
2011 Spring Semester
Homework 1, Due: Mar 2
Problem 1 25%. Let TA(n) and TB(n) denote the time complexities of two algorithms A and B
respectively, with respect to the input size n. For each case, specify which a

THE HONG KONG UNIVERSITY OF SCIENCE & TECHNOLOGY
Department of Computer Science & Engineering
COMP 271: Design and Analysis of Algorithms
Fall 2010
Final Examination
Instructor: James Kwok (L1) / Huamin Qu (L2)
Date: Friday, 17 Dec. 2010
Time: 16:30 19:30

THE HONG KONG UNIVERSITY OF SCIENCE & TECHNOLOGY
Department of Computer Science & Engineering
COMP 271: Design and Analysis of Algorithms
Fall 2010
Final Examination
Instructor: James Kwok (L1) / Huamin Qu (L2)
Date: Friday, 17 Dec. 2010
Time: 16:30 19:30

COMP 271 Design and Analysis of Algorithms
(Real) Fall 2009 Final Exam
1. Quick-Answer Questions (3 4 = 12 pts)
For each question below, write down the asymptotic (using ) result. You do not need to
justify your answers.
1.1 What is the solution of the re

COMP271 Fall 2009 Final Exam Solutions
1 1.1 (n)
1.2 (1)
1.3 (n + m log m)
1.4 expected: (n log n), worst-case: (n2 )
2 2.1 True
2.2 Unknown
2.3 False. Some NP-hard problems are more dicult than NP-complete problems.
2.4 True
3 Divide the
n n cells into 4