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))
pacificrack官方在搞2021年七夕促销,两款便宜vps给的配置都是挺不错的,依旧是接入1Gbps带宽,KVM虚拟、纯SSD raid10阵列,支持包括Linux、Windows 7、10、server2003、2008、2012、2016、2019在内多种操作系统。本次促销的VPS请特别注意限制条件,见本文末尾!官方网站:https://pacificrack.com支持PayPal、支...
buyvm的第四个数据中心上线了,位于美国东南沿海的迈阿密市。迈阿密的VPS依旧和buyvm其他机房的一样,KVM虚拟,Ryzen 9 3900x、DDR4、NVMe、1Gbps带宽、不限流量。目前还没有看见buyvm上架迈阿密的block storage,估计不久也会有的。 官方网站:https://my.frantech.ca/cart.php?gid=48 加密货币、信用卡、PayPal、...
硅云怎么样?硅云是一家专业的云服务商,硅云的主营产品包括域名和服务器,其中香港云服务器、香港云虚拟主机是非常受欢迎的产品。硅云香港可用区接入了中国电信CN2 GIA、中国联通直连、中国移动直连、HGC、NTT、COGENT、PCCW在内的数十家优质的全球顶级运营商,是为数不多的多线香港云服务商之一。目前,硅云香港云服务器,CN2+BGP线路,1核1G香港云主机仅188元/年起,域名无需备案,支持个...
graphsearch为你推荐
学生微信5朝阳分局电子物证实验室建设项目ipad如何上网IPAD4怎样上网?重庆电信宽带管家如何才能以正确的流程在重庆电信安装上宽带xp系统关闭445端口xp中,如何关闭掉一些没有用的端口,请高手解答?联通iphone4联通iphone4好用吗苹果5.1完美越狱iOS5.1.1完美越狱教程routeadd30分,route add 命令,会的帮我!chrome18CHROME现在最新版是多少?搜狗拼音输入法4.3搜狗拼音输入法怎样快速输入特殊邮箱号?
php网站空间 hostigation 域名商 justhost 韩国电信 老左博客 地址大全 网站挂马检测工具 web服务器架设 刀片式服务器 169邮箱 idc是什么 腾讯实名认证中心 lamp架构 asp.net虚拟主机 热云 遨游论坛 文件传输 ddos攻击教程 主机托管 更多