南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)算法的正确性

计算机问题求解一论题2-1 -算法的正确性 2020年2月27日
计算机问题求解 – 论题2-1 - 算法的正确性 2020年2月27日

问题1: 人们似乎对于计算机 “犯错比对于人犯错更 加苛刻,这是为什么呢?

几种不同的错误 “语言错” 口很容易被语言处理软件发现,甚至自动纠正。 “语义错” 口▣合格的程序员很少会犯这类错误。 ▣解题逻辑错误 口“粗心”造成的错误。 常见(相对来说) “真正的”逻辑错误。 逻辑错误不常见,但这个是真的“伤脑筋”!
几种不同的错误 ◼ “语言错” ❑ 很容易被语言处理软件发现,甚至自动纠正。 ◼ “语义错” ❑ 合格的程序员很少会犯这类错误。 ◼ 解题逻辑错误 ❑ “粗心”造成的错误。 ◼ 常见(相对来说) ❑ “真正的”逻辑错误。 逻辑错误不常见,但这个是真的“伤脑筋”!

问题2: 书上的对文本中出现“money一词的句子计数的 例子出现了什么样的错误,你能说出它的性质吗?

Test and debugging A designer might try out an algorithm on several typical and atypical inputs and to find the error.In fact,a programmer will normally test a program on numerous inputs,sometimes called test sets,and will gradually rid it of its language errors and most of its logical errors. ■Test是一种合理的获得“正确”程序的方法吗? 口程序是一种人工制品。既然如此,通过实验观察,应该可以得到这个“物体 ”的某些属性 How to“gradually rid it of its errors”? a Debug!
Test and debugging ◼ A designer might try out an algorithm on several typical and atypical inputs and to find the error. In fact, a programmer will normally test a program on numerous inputs, sometimes called test sets, and will gradually rid it of its language errors and most of its logical errors. ◼ Test 是一种合理的获得“正确”程序的方法吗? ❑ 程序是一种人工制品。既然如此,通过实验观察,应该可以得到这个“物体 ”的某些属性 ◼ How to “gradually rid it of its errors”? ❑ Debug!

关于debugging的思考 a什么是debug? The process of repeatedly executing an algorithm,or running a program,with the intention of finding and eliminating errors is called debugging ■为什么我们可以依赖debug来排除错误? 口程序运行的“再现”==》错误的“再现
关于debugging的思考 ◼ 什么是debug? ❑ The process of repeatedly executing an algorithm, or running a program, with the intention of finding and eliminating errors is called debugging ◼ 为什么我们可以依赖debug来排除错误? ❑ 程序运行的“再现”==》错误的“再现

Test和Debugging的局限性 Most algorithmic problems have infinite sets of legal inputs, and hence infinitely many candidate test sets,each of which has the potential of exposing a new error. Dijkstra: Program testing can be used to show the presence of bugs, but never to show their absence! 我们能够用形式系统“翻译”Dijkstral的话吗?
Test和Debugging 的局限性 Dijkstra: Program testing can be used to show the presence of bugs, but never to show their absence! 我们能够用形式系统“翻译”Dijkstra的话吗? Most algorithmic problems have infinite sets of legal inputs, and hence infinitely many candidate test sets, each of which has the potential of exposing a new error

Infinite computation Infinite computation为什么有时也会被称为infinite loop? "以下两个例子都会形成一个infinite computation,区别在哪? while(1)do {... for(int i=0;i==9;++)1...;i++;... ■如何规避“死循环”? 口算法级 循环出口必达 ▣不合适的出口标准;循环体内使用控制变量;.. 口编程级 ■细心;循环控制中,少用“高级”的语言设施;
Infinite computation ◼ Infinite computation为什么有时也会被称为infinite loop? ◼ 以下两个例子都会形成一个infinite computation,区别在哪? ❑ while(1) do {…} ❑ for(int i=0;i==9;i++) {…;i++;…} ◼ 如何规避“死循环”? ❑ 算法级 ◼ 循环出口必达 ❑ 不合适的出口标准;循环体内使用控制变量;…… ❑ 编程级 ◼ 细心;循环控制中,少用“高级” 的语言设施;……

Test和debug的局限性 s Debug必须以测试出的错误的可再现为前提 口只有封闭环境、确定运行,才能“再现”错误 ·开放式环境中运行的程序,debug异常困难 口分布式系统、网络平台等 ■ 确定输入,但运行时刻数据非“独占” 口非确定环境下运行的程序 ■本质上输入数据无法保证确定性 ·必须随机的算法 口程序执行存在非确定性
Test和debug的局限性 ◼ Debug 必须以测试出的错误的可再现为前提 ❑ 只有封闭环境、确定运行,才能“再现”错误 ◼ 开放式环境中运行的程序,debug异常困难 ❑ 分布式系统、网络平台等 ◼ 确定输入,但运行时刻数据非“独占” ❑ 非确定环境下运行的程序 ◼ 本质上输入数据无法保证确定性 ◼ 必须随机的算法 ❑ 程序执行存在非确定性

程序和算法正确性保障: ·自动验证: some sort of super-algorithm that ace inputs a description of a hm A that is proposed a( 当我们完成了某个算法 solves P. 的正确性证明,我们 "人工证明 test的,debug的是什 Can we ob 么? Je correct?Is there any way in wor eformal, mathematical techniques to realize this objective?
程序和算法正确性保障: ◼ 自动验证: ❑ some sort of super-algorithm that would accept as inputs a description of an algorithmic problem P and an algorithm A that is proposed as a solution, and would determine if indeed A solves P. ◼ 人工证明: ❑ Can we ourselves prove our algorithms to be correct? Is there any way in which we can use formal, mathematical techniques to realize this objective? 当我们完成了某个算法 的正确性证明,我们 test的,debug的是什 么?
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)算法的效率 Efficiency(简版).pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)算法的效率 Efficiency.pdf
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)分治法与递归.pptx
- 《计算机问题求解》课程教学资源(参考书籍)Proofs from THE BOOK(Fifth Edition,Martin Aigner · Günter M. Ziegler).pdf
- 《计算机问题求解》课程参考书籍资料:《Mathematics for Computer Science》PDF电子书(revised Wednesday 6th June, 2018,Eric Lehman、F Thomson Leighton、Albert R Meyer).pdf
- 《计算机问题求解》课程教学资源:《An Introduction to the Analysis of Algorithms》参考书籍教材(Second Edition,Robert Sedgewick、Philippe Flajolet).pdf
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)布尔代数.pptx
- 《计算机问题求解》课程教学资源(阅读材料)THE CLASSIC WORK EXTENDED AND REFINED《The Art of Computer Programming》Vol4A Combinatorial Algorithms Part 1(DONALD E.KNUTH).pdf
- 《计算机问题求解》课程教学资源(阅读材料)Programming Pearls, Second Edition by Jon Bentley. Addison-Wesley, Inc., 2000.pdf
- 《计算机问题求解》课程教学资源:《Concrete Mathematics:A Foundation for Computer Science》参考书籍教材(Ronald L. Graham、Donald E. Knuth、Oren Patashnik).pdf
- 《计算机问题求解》课程参考书籍教材:Abstract Data Types and Algorithms(Second Edition,Manoochehr Azmoodeh).pdf
- 《计算机问题求解》课程教学资源:《Discrete Mathematics for Computer Scientists》参考书籍教材(Stein、DrysdaleBogart).pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)集合论(IV)无穷 Infinity(简版).pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)集合论(IV)无穷 Infinity.pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)集合论(III)函数 Function(简版).pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)集合论(III)函数 Function.pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)集合论 II 关系 Relation(简版).pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)集合论 II 关系 Relation.pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)集合论 I 公理与操作(简版).pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)集合论 I 公理与操作.pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)组合与计数 Counting.pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)组合与计数 Counting(简版).pdf
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)递归及其数学基础(part-1).pptx
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)递归及其数学基础 linear-recurrences.pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)递归及其数学基础 linear-recurrences(简版).pdf
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)算法方法.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)概率分析与随机算法.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)离散概率基础.pptx
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)排序与选择算法 sorting and selection.pdf
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)排序与选择算法 sorting and selection(简版).pdf
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)基本数据结构.pptx
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)堆的结构、实现以及算法应用 Heap & HeapSort.pdf
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)B树.pptx
- 南京大学:《计算机问题求解》课程教学资源(课件讲稿)Hashing方法.pdf
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)搜索树.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)红黑树.pptx
- 《计算机问题求解》课程参考书籍教材:《Introduction to Algorithms》PDF电子版(Third Edition,Thomas H. Cormen、Charles E. Leiserson、Ronald L. Rivest、Clifford Stein).pdf
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)动态规划.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)红黑树.pptx
- 南京大学:《计算机问题求解》课程教学资源(PPT课件讲稿)图的基本概念.pptx