1 / 18

Intro to Computer Algorithms Lecture 17

Intro to Computer Algorithms Lecture 17. Phillip G. Bradford Computer Science University of Alabama. Announcements. Advisory Board’s Industrial Talk Series http://www.cs.ua.edu/9IndustrialSeries.shtm 4-Nov: Bill Engelke, Mercedes-Benz, USA. Next Research Colloquia:

koko
Download Presentation

Intro to Computer Algorithms Lecture 17

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Intro to Computer Algorithms Lecture 17 Phillip G. Bradford Computer Science University of Alabama

  2. Announcements • Advisory Board’s Industrial Talk Series • http://www.cs.ua.edu/9IndustrialSeries.shtm • 4-Nov: Bill Engelke, Mercedes-Benz, USA. • Next Research Colloquia: • Prof. Nael Abu-Ghazaleh • 10-Nov @ 11:00am • “Active Routing in Mobile Ad Hoc Networks”

  3. Computer Security Research Group • Meets every Friday from 11:00 to 12:00 • In 112 Houser • Computer Security, etc. • Email me to be on the mailing list!

  4. CS Story Time • Prof. Jones’ research group • See http://cs.ua.edu/StoryHourSlide.pdf

  5. Next Midterm • Tuesday before Thanksgiving ! • 25-November

  6. Outline

  7. Dynamic Programming • Principle of optimality • Consider any well-formed substructure s of an optimal structure S • Then s is optimal itself. • This allows the combination of well-formed substructures into optimal superstructures

  8. Dynamic ProgrammingComputing Binomial Coefficients • For i1 to n do • For j 0 to min(i,k) do • If j=0 or j=k, then • C[i,j]  1 • Else • C[i,j]  C[i-1,j-1] + C[i-1,j] • Endif • Endfor • Endfor • Return C[n,k]

  9. What does this cost? • O(nk) • How about (corrected) exercise #6 in the book? Measure rec-calls instead • Omega(nk) for k constant, n varying • For general analyses, Beware of memoization! • Analyses may not reflect running times

  10. Warshall’s and Floyd’s Algs. • Adjacency Matrices Columns (to) 1 n 2 1 2 3 Rows (from) n

  11. Transitive Closure • When We work with directed graphs • Call them digraphs • Transitive closure T of a digraph is an nxn boolean matrix: • T[i,j]=1 iff there is a non-trivial path between nodes i and j. • T[i,j]=0 iff there is No path between nodes i and j (and i != j).

  12. Transitive Closure • All Pairs Shortest Path Problems • Different from Single Source Shortest Paths

  13. How to get a Transitive Closure? • How about DFS and BFS? • What about the principle of optimality? • The matrix R(k) is all paths with up to k intermediary nodes • R(0) is the adjacency matrix • R(1) is the adjacency matrix “along with” any paths that are extended by one using node 1. • OR…

  14. Transitive Closure via Warshall • R(2) is all shortest paths using nodes 1 and 2 as intermediaries • R(3) is all shortest paths using nodes 1,2, and 3 as intermediaries • … • R(n) is all shortest paths using nodes 1,2,…,n as intermediaries

  15. Basis for Warshall’s Algorithm • R(k)i,j = • = R(k-1)i,j OR [ R(k-1)i,k AND R(k-1)k,j ] • If R(k-1)i,j = 1, then R(k)i,j = 1 • Say R(k-1)i,j = 0, so R(k)i,j = 1 • iff R(k-1)i,k = 1 and R(k-1)k,j = 1 • Why?

  16. Warshall’s Algorithm • R(0)  Adjacency Matrix • For k  1 to n do • For i 1 to n do • For j  1 do n do • R(k)i,j R(k-1)i,j OR [ R(k-1)i,k AND R(k-1)k,j ] • Endfor • Endfor • Endfor • Return R(n)

  17. Floyd’s Algorithm • Weighted (non-directed) graph • No cycles of negative length • Looks like (Min,+) “matrix multiplication”

  18. Floyd’s Algorithm • DWeighted Adj. Matrix, augmented by Infinity • For k  1 to n do • For i  1 do n do • For j  1 to n do • D[i,j]  min{ D[i,j], D[i,k] + D[k,j] } • Endfor • Endfor • Endfor • Return D

More Related