Assignment12SampleproblemsSampleproblemsGraphSearchGraphSearchInthefollowinggraphs,assumethatifthereiseverachoiceamongstmultiplenodes,boththeBFSandDFSalgorithmswillchoosetheleft-mostnodefirst.
Startingfromthegreennodeatthetop,whichalgorithmwillvisittheleastnumberofnodesbeforevisitingtheyellowgoalnodeA:BFSB:DFSC:NeitherBFSnorDFSwilleverencounterthegoalnodeinthisgraph.
C:NeitherBFSnorDFSwilleverencounterthegoalnodeinthisgraph.
D:BFSandDFSencountersamenumberofnodesbeforeencounterthegoalnodeA:BFSB:DFSC:NeitherBFSnorDFSwilleverencounterthegoalnodeinthisgraph.
C:NeitherBFSnorDFSwilleverencounterthegoalnodeinthisgraph.
D:BFSandDFSencountersamenumberofnodesbeforeencounterthegoalnodeTheanswerisBFSHowcanwegetForBFSalgorithm,visitinganode'ssiblingsbeforeitschildren,whileinDFSalgorithm,visitinganode'schildrenbeforeitssiblingsBeforecounteringgoalnodeBeforecounteringgoalnodeF:BFSalgorithmencountersnodes:ABCDEDFSalgorithmencountersnodes:ABDHLIEJMCInthefollowinggraphs,assumethatifthereiseverachoiceamongstmultiplenodes,boththeBFSandDFSalgorithmswillchoosetheleft-mostnodefirst.
Startingfromthegreennodeatthetop,whichalgorithmwillvisittheleastnumberofnodesbeforevisitingtheyellowgoalnodeA:BFSB:DFSC:NeitherBFSnorDFSwilleverencounterthegoalnodeinthisgraph.
C:NeitherBFSnorDFSwilleverencounterthegoalnodeinthisgraph.
D:BFSandDFSencountersamenumberofnodesbeforeencounterthegoalnodeA:BFSB:DFSC:NeitherBFSnorDFSwilleverencounterthegoalnodeinthisgraph.
C:NeitherBFSnorDFSwilleverencounterthegoalnodeinthisgraph.
D:BFSandDFSencountersamenumberofnodesbeforeencounterthegoalnodeTheanswerisDFSHowcanwegetForBFSalgorithm,visitinganode'ssiblingsbeforeitschildren,whileinDFSalgorithm,visitinganode'schildrenbeforeitssiblingsBeforecounteringgoalnodeBeforecounteringgoalnodeG:BFSalgorithmencountersnodes:ABCDEFDFSalgorithmencountersnodes:ABDConsiderthefollowinggraph.
IfthereiseveradecisionbetweenmultipleneighbornodesintheBFSorDFSalgorithms,assumewealwayschoosetheletterclosesttothebeginningofthealphabetfirst.
InwhatorderwillthenodesbevisitedusingaBreadthFirstSearchInwhatorderwillthenodesbevisitedusingaDepthFirstSearchConsiderthefollowinggraph.
IfthereiseveradecisionbetweenmultipleneighbornodesintheBFSorDFSalgorithms,assumewealwayschoosetheletterclosesttothebeginningofthealphabetfirst.
InwhatorderwillthenodesbevisitedusingaBreadthFirstSearchTheansweris:ABDCEGHFInwhatorderwillthenodesbevisitedusingaDepthFirstSearchTheansweris:ABCEHFGDHowcanwegetA->B->DB->C->E->GD->CC->AE->HE->HG->FH->F->GSoforBFS,theanswerisABDCEGHFforDFS,theanswerisABCEHFGDShootingballoonShootingballoonSupposeyouareplayinggameofshootingballoon.
Youexpecttoshootnballoonsintheboard,assumingyouaresharpshooter,100%hit.
Therearetwoscenarios,youneedfindtheappropriateBigOhnotationforeachscenario.
Intheseproblems,oneunitofworkisshootingoneballoon.
unitofworkisshootingoneballoon.
Scenario1:Forevery2balloonsyouareabletoshoot,onenewballoonisinsertedintheboard.
So,iftherewere20balloons,afteryoushootthefirst2,thereare19ontheboard.
Afteryoushootthenext2,thereare18ontheboard.
HowmanyballoonsdoyoushootbeforetheboardisemptybeforetheboardisemptyA:O(1)B:O(n)C:O(lgn)D:O(n)Scenario1:Forevery2balloonsyouareabletoshoot,onenewballoonisinsertedintheboard.
So,iftherewere20balloons,afteryoushootthefirst2,thereare19ontheboard.
Afteryoushootthenext2,thereare18ontheboard.
HowmanyballoonsdoyoushootbeforetheboardisemptyA:O(1)B:O(n)B:O(n)C:O(lgn)D:O(n)ifOneballoonontheboard,youshoot1balloonintotal,iftwoballoonsontheboard,youshoot3balloons,ifthreeballoonsontheboard,youshoot5balloonsintotal.
Sofollowit,youshoot2*n-1balloonsintotal.
Scenario2:Bythetimeyouhaveshootthefirstnballoons,n-1newballoonshavebeeninsertedontheboard.
Aftershootingthosen-1balloons,therearen-2newballoonsareinsertedontheboard.
Aftercheckingoutthosen-2balloons,therearen-3newballoonsontheboard.
Thissamepatterncontinuesuntilonnewballoonareinsertedontheboard.
Howmanytotalballoonsdoyouontheboard.
HowmanytotalballoonsdoyoushootbeforetheboardisemptyA:O(1)B:O(n)C:O(lgn)D:O(n)Scenario2:Bythetimeyouhaveshootthefirstnballoons,n-1newballoonshavebeeninsertedontheboard.
Aftershootingthosen-1balloons,therearen-2newballoonsareinsertedontheboard.
Aftercheckingoutthosen-2balloons,therearen-3newballoonsontheboard.
Thissamepatterncontinuesuntilonnewballoonareinsertedontheboard.
HowmanytotalballoonsdoyoushootbeforetheboardismanytotalballoonsdoyoushootbeforetheboardisemptyA:O(1)B:O(n)C:O(lgn)D:O(n)(n+n-1+n-2+n-3+……+n-(n-1)+n-(n))=(n*n-(n*(n+1)/2))
LayerStack(成立于2017年),当前正在9折促销旗下的云服务器,LayerStack的云服务器采用第 3 代 AMD EPYC™ (霄龙) 处理器,DDR4内存和企业级 PCIe Gen 4 NVMe SSD。数据中心可选中国香港、日本、新加坡和洛杉矶!其中中国香港、日本和新加坡分为国际线路和CN2线路,如果选择CN2线路,价格每月要+3.2美元,付款支持paypal,支付宝,信用卡等!...
BuyVM测评,BuyVM怎么样?BuyVM好不好?BuyVM,2010年成立的国外老牌稳定商家,Frantech Solutions旗下,主要提供基于KVM的VPS服务器,数据中心有拉斯维加斯、纽约、卢森堡,付费可选强大的DDOS防护(月付3美金),特色是1Gbps不限流量,稳定商家,而且卢森堡不限版权。1G或以上内存可以安装Windows 2012 64bit,无需任何费用,所有型号包括免费的...
我们一般的站长或者企业服务器配置WEB环境会用到免费版本的宝塔面板。但是如果我们需要较多的付费插件扩展,或者是有需要企业功能应用的,短期来说我们可能选择按件按月付费的比较好,但是如果我们长期使用的话,有些网友认为选择宝塔面板企业版或者专业版是比较划算的。这样在年中大促618的时候,我们也可以看到宝塔面板也有发布促销活动。企业版年付899元,专业版永久授权1888元起步。对于有需要的网友来说,还是值...
graphsearch为你推荐
微信小程序直播功能准入要求支持ipad支持ipad重庆宽带测速重庆云阳电信宽带测速网址谁知道,帮个忙?ipadwifiipad的wifi打不开怎么办?iphonewifi苹果手机突然用不了Wi-Fi了googleadsense·什么是Google AdSense?如何加入Google AdSense? 谁可以告诉我吗?firefoxflash插件火狐浏览器怎么安装flashwin7还原系统win7系统怎么恢复出厂设置ios10.0.3小六升IOS11.0.3到底卡不卡,过来人给个建议
网络服务器租用 云服务器租用 域名拍卖 xenvps edgecast photonvps Dedicated themeforest 国外空间 论坛空间 个人空间申请 空间论坛 网站cdn加速 卡巴斯基免费试用版 江苏双线服务器 畅行云 卡巴斯基官网下载 apnic 网站防护 上海联通 更多