Balaji Raghavachari 199 Algorithm Design and Analysis
BellmanFord Example Balaji Raghavachari 201 Algorithm Design and Analysis
DAG-ShortestPath Example
Topological order: s,33,y,z,t. Balaji Raghavachari 211 Algorithm Design and Analysis
w
W
H I .
W 55 L
Course Syllabus
CS 6363.004 Design and analysis of computer algorithms; Spring 2017; TR 10:00-11:15 AM; ECSS 2.415;
Class URL:
http:/www.utdallas.edu/~rbk/teach/2017s/daca.html
Professor Contact Information
Balaji Raghavachari; (972) 883-2136; [email protected]
Show that the number of iterations is nite separately, or include it as part of the LI.
LI: Linear search
LinearSearch(A, n, x): / Search for x in A[1.n]
Precondition: none
1: for i 1 to n do
2:
if A[i] = x then
3:
return true
4: return false
LI: Binary s
LI: Insertion sort
InsertionSort(A, n): / Sort A[1.n].
1: for j 2 to n do
2:
key A[j]
3:
ij1
4:
while i > 0 and A[i] > key do
5:
A[i + 1] A[i]
6:
ii1
7:
A[i + 1] key
Analysis of while loop:
Precondition to the while loop: key = A[j], i = j 1, and, A[1.j 1
Strongly connected components
DFS_SCC (G)
for u V(G) do u.color White
/ global vars
cno 0; pass1 true
s new Stack<Vertex>
/ Pass 1
for u V(G) do
if u.color = White then
DFS_Visit (u)
/ Pass 2
ReverseGraph(G); pass1 false
for u V(G) do u.color White
for u
DFS: components
DFS (G)
for u V(G) do
u.color White
u. null
/ global vars
time 0
cno 0
DFS_Visit (u)
u.color Gray
u.dis + time
u.cno cno
for each e=(u,v) Adj[u] do
if v.color = White then
v. u
DFS_Visit (v)
DFS: edge classification
DFS (G) / undirected gr
c Balaji Raghavachari
3
Algorithm Design and Analysis
RT analysis: Merge algorithm
Algorithm M erge(A, p, q, r)
1:
2:
3:
4:
5:
6:
7:
8:
9:
Copy A[p.q] into L[1.q p + 1]
Copy A[q + 1.r] into R[1.r q]
Set sentinels L[q p + 2] = R[r q + 1] =
i 1;
j1
for k