CS 401
Midterm review
Xiaorui Sun
1
CS 401 Midterm review Xiaorui Sun 1 Midterm Exam Midterm exam via - - PowerPoint PPT Presentation
CS 401 Midterm review Xiaorui Sun 1 Midterm Exam Midterm exam via gradescope : October 16 (Friday) The exam will be available on Oct 16 0am You must submit no later than Oct 16 11:59pm Usually can be finished in 2 hours
Xiaorui Sun
1
from 1pm to 4pm.
your handwriting to gradescop
your handwriting to gradescope
each question, no justification/correctness proof
3
4
5
6
7
(/3
8
" terms "/2 terms This method does not work when log ! " = Θ(log & " )
V = {1, 2, 3, 4, 5 ,6, 7, 8} E = {(1,2), (1,3), (2,3), (2,4), (2,5), (3,5), (3,7), aaaa(3,8), (4,5), (5,6), (7,8)} m=11, n=8 No self-loop, no multiedge
10
11
14
15
BFS Tree gives shortest paths from 1 to all vertices
All edges connect same
16
17
Edge code: Tree edge Back edge
18
19
No self-loop, no multiedge (8, 10) and (10, 8) are different edges
20
a DAG
2 3 6 5 4 7 1
a topological ordering of that DAG– all edges left-to-right
1 2 3 4 5 6 7
Cost of path s-2-3-4-t = 9 + 23 + 6 + 6 = 44.
s 3 t 2 6 7 4 5 23 18 2 9 14 15 5 30 20 44 16 11 6 19 6 length of path = sum of edge weights in path
22
& !
23
24
Interval Scheduling
25
Time 1 2 3 4 5 6 7 8 9 10 11
f g h e a b c d h e b
Every step we consider a single job In each step, we decide if the job will be in the solution set
into the solution set How do we order jobs?
26
27
Typically, each sub-problem is at most a constant fraction of the size of the original problem
n n/2 n/2 n/4
% & + (") for all " > +. Then,
30
31
32
33
last element of the first half ([6, -2] is the interval of [-2, -5, -6, -2] that (1) contains the last element and (2) has the largest sum)
the first element of the second half
34
35
!/0": sum of all the elements in the first half !/0&: sum of all the elements in the second half