我系李曾妍老师在首届全国高校青年教师教学竞赛中获二等奖课件汉.ppt

我系李曾妍老师在首届全国高校青年教师教学竞赛中获二等奖课件汉.ppt

  1. 1、本文档共16页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
* 前面的知识点 例题:用递归的方法求fac(n)=n! 如: 10!= 10*9! 9! = 9*8! … … 2! = 2*1! 1! =1 1 (n = 1) n*fac(n-1) (n 1) fac(n) = 边界条件 递归公式 Solution(解决方法) of recursion program: find the recursion formula(递归公式). confirm the ending condition(边界条件) of recursion algorithm. Use recursion in Hanoi Tower Problem (用递归解决汉诺塔问题) * A杆 C杆 B杆 if A has N(N1) disks ,divide it into 2 parts: top N-1 disks, and bottom disk. 63(N-1) 64(N) ② move the bottom disk: from A,to C ③ move the top N-1 disks: from B,using A,to C ① move the top N-1 disks: from A,usingC,to B 1、Analysis(分析): * recursion formula (递归公式) if ( n 1 ) hanoi ( n-1, A,C,B ); printf(%c ? %c\n, A, C); hanoi ( n-1, B,A,C ); Ending condition(边界条件) if ( n == 1 ) printf( %c ? %c\n,A, C); solution (解决方法) : * void hanoi(int n,char A,char B,char C) { if ( n1 ) { hanoi ( n-1, A, C, B ); printf(%d: %c - %c\n,++i,A, C); hanoi ( n-1, B, A, C ); } else printf(%d: %c - %c\n,++i,A,C); } 2、Programming(编写程序): A B C Hanoi demo hanoi(3,A,B,C) hanoi(2,A,C,B) hanoi(1,A,B,C) A?C hanoi(1,C,A,B) A ? B hanoi(2,B,A,C) C ? B A?C hanoi(1,B,C,A) B ? A B ? C hanoi(1,A,B,C) A ? C step(64) =step(63)+1+step(63) step(1) =1 step(2) =1+1+1=3 step(63) =step(62)+1+step(62) … step(2) =step(1)+1+step(1) step(63) = 263-1 step(64) = 264-1 … Time complexity: O(2n) 3、Complexity analysis of algorithm(算法复杂度分析): 移动64个盘子需要: 264-1=1844亿亿次。 如果每次移动用1秒,需要5800亿年。 如果利用超级计算机“天河一号”,需要数小时。 天河一号:测运算速度达每秒2570万亿次。 recursion formula (递归公式) ending condition(边界条件) 4、Summary(小结) time complexity of algorithm (算法时间复杂度) solution (解决方法) O(2n) 作业:编程设计一个Hanoi小游戏。 5、 Programming exercise * C语言程序设计 ——双语专业课 * Chapter17:Recursion (递归) Hanoi Tower Problem (汉诺塔问题) 故事开始于古印度…… 相传在创世纪时代, 有一座神庙, 据说它是宇宙的中心。 神庙里竖立着三根银杆, 有64个大小都不同的金盘, 每一个金盘正中央都有一个洞, 依“大盘在下,小盘在上 ”的顺序 放在同一根银杆上。

文档评论(0)

yuxiufeng + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档