资源描述:
《lecture 19 shortest paths iii all-pairs shortest paths, matrix multiplication, floyd-warshall, johns》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、MITOpenCourseWarehttp://ocw.mit.edu6.046JIntroductiontoAlgorithms,Fall2005Pleaseusethefollowingcitationformat:ErikDemaineandCharlesLeiserson,6.046JIntroductiontoAlgorithms,Fall2005.(MassachusettsInstituteofTechnology:MITOpenCourseWare).http://ocw.mit.edu(accessedMMDD,YYYY).Licen
2、se:CreativeCommonsAttribution-Noncommercial-ShareAlike.Note:Pleaseusetheactualdateyouaccessedthismaterialinyourcitation.FormoreinformationaboutcitingthesematerialsorourTermsofUse,visit:http://ocw.mit.edu/termsMITOpenCourseWarehttp://ocw.mit.edu6.046JIntroductiontoAlgorithms,Fall
3、2005Transcript–Lecture19--shortestpaths.Thisisthefinale.Hopefullyitwasworthwaitingfor.Remindyouthere'saquizcomingupsoon,youshouldbestudyingforit.There'snoproblemsetdueatthesametimeasthequizbecauseyoushouldbestudyingnow.It'satake-homeexam.It'srequiredthatyoucometoclassonMonday.Of
4、course,you'llallcome,buteveryonewatchingathomeshouldalsocomenextMondaytogetthequiz.It'stherequiredlecture.So,weneedabitofarecapinthetrilogysofar.So,thelasttwolectures,thelasttwoepisodes,oraboutsinglesourceshortestpaths.So,wewantedtofindtheshortestpathfromasourcevertextoeveryothe
5、rvertex.And,wesawafewalgorithmsforthis.Here'ssomerecap.Wesawintheunweightedcase,thatwassortoftheeasiestwherealltheedgeweightswereone.Thenwecouldusebreadthfirstsearch.Andthiscostswhatwecalllineartimeinthegraphworld,thenumberofverticesplusthenumberofedges.Thenextsimplestcase,perha
6、ps,isnonnegativeedgeweights.Andinthatcase,whatalgorithmdoweuse?Dijkstra,allright,everyone'sawake.Severalanswersatonce,great.Sothistakesalmostlineartimeifyouuseagoodheapstructure,so,VlogVplusE.And,inthegeneralcase,generalweights,wewoulduseBellman-Fordwhichyousaw.AndthatcostsVE,go
7、od,OK,whichisquiteabitworse.Thisisignoringlogfactors.Dijkstraisbasicallylineartime,Bellman-Fordyou'requadraticifyouhaveaconnectedgraph.So,inthesparsecase,whenEisorderV,thisisaboutlinear.Thisisaboutquadratic.Inthedensecase,whenEisaboutV^2,thisisquadratic,andthisiscubic.So,Dijkstr
8、aandBellman-FordareseparatedbyaboutanorderofVfa