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
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
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
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 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
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 271 Design and Analysis of Algorithms
Fall 2008 Midterm Exam
1. Multiple Choice (50 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 letter that c
COMP 271 Design and Analysis of Algorithms
Fall 2008 Midterm Exam Solutions
1. Multiple Choice
1.1 (d) 1.2 (c) 1.3 (c) 1.4 (e) 1.5 (a) 1.6 (c) 1.7 (d) 1.8 (e) 1.9 (d) 1.10 (a)
2. If n 3 we can solve the problem trivially. Let m = n/2. We look at the three
COMP 3711 Design and Analysis of Algorithms
Fall 2011
Solutions to Homework 4
1. Give an O(n2 ) time dynamic programming algorithm to nd the longest monotonically increasing subsequence of a sequence of n numbers (i.e, each successive number
in the subseq
COMP 3711 Design and Analysis of Algorithms
Fall 2011
Assignment 4
Note: Please write down your section number (L1 or L2) and student ID clearly on
your homework so that we can correctly record your score.
1. Design an O(n2 ) time dynamic programming algo
COMP271: Design and Analysis of Algorithms
Solutions of Homework 4
COMP271: Design and Analysis of Algorithms
Solutions of Homework 4
1
COMP271: Design and Analysis of Algorithms
Solutions of Homework 4
Question 1
The longest monotonically increasing subs
COMP 271 Design and Analysis of Algorithms
2011 Spring Semester
Homework 4, Due: May 12
Problem 1 20%. Design a dynamic programming algorithm to find the longest
monotonically increasing subsequence of a sequence of n numbers (i.e., each
successive number
COMP 3711 Design and Analysis of Algorithms
Fall 2011
Homework 2 Solution
Solution 1: (a)
(b)
- In the worst case scenario, the partition is totally unbalanced. Then the number
of pivots will be n 1 (all numbers except the smallest one will be picked as t
COMP 3711 Design and Analysis of Algorithms
Fall 2011
Homework 2
1. Quicksort and Randomized-Quicksort
(a) When Randomized-Quicksort runs, how many calls are made to the random-number
generator random() in the worst case? How about in the best case? Give